471,089 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Listing Entities and Attributes from a XML Schema

Hi all..

..NET + MSXML platform....VB

Need to build a list of all the entities and attributes to allow the user to
do search...how can i do that from the schema ??

Cheers
Rohit
Nov 11 '05 #1
3 1632
Rohit Sharma wrote:
.NET + MSXML platform....VB
Are you sure you are using MSXML? Actually .NET doesn't include MSXML in any form.
Need to build a list of all the entities and attributes to allow the user to
do search...how can i do that from the schema ??

Could you provide some sample of what are you looking for? It's not clear,
whether you need all attributes in schema file or all attributes, declared in
schema file?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
Rohit Sharma wrote:
Then for each of them i need the attributes...like
Product : -> ID
Product: -> Product_Name
Product: -> description

and so on...
That's pretty easy. Learn about Schema object model (SOM) and
System.Xml.Schema namespace. The idea is to read schema file, compile it into
an object model, then for each complex type defined iterate over its declared
attributes:
public class Class1 {
public static void Main(string[] args) {
XmlSchema schema = XmlSchema.Read(new
StreamReader("LPD_PLCS_Schema.xsd"),
new ValidationEventHandler(ShowCompileError));
schema.Compile(new ValidationEventHandler(ShowCompileError));
foreach (XmlSchemaType t in schema.SchemaTypes.Values) {
XmlSchemaComplexType type = t as XmlSchemaComplexType;
if (type != null) {
foreach (XmlSchemaAttribute attr in type.Attributes)
Console.WriteLine("{0}:->{1}", type.Name, attr.Name);

}
}
}
private static void ShowCompileError(object sender, ValidationEventArgs e) {
Console.WriteLine("Validation Error: {0}", e.Message);
}

}

Note, that one cannot use xs:anySimpleType type directly in schema using .NET.
It's "implied" type, each simple type derives from by definition. So change
<xs:element name="Value_component" type="xs:anySimpleType"/>
to
<xs:element name="Value_component"/>

With this change code above produces:
Unit:->id
System_breakdown:->id
Document_version:->id
Breakdown_element_realization:->id
Date_or_date_time_assignment:->id
System_element_version:->id
System_breakdown_context:->id
Part_view_definition:->id
View_definition_context:->id
Product:->id
PLCS_Part:->id
Document_assignment:->id
System_element:->id
Document:->id
Calendar_date:->id
Digital_file:->id
Next_assembly_usage:->id
Value_with_unit:->id
Identification_assignment:->id
Part_version:->id
Digital_document_definition:->id
System_element_usage:->id
System_breakdown_version:->id
System_element_definition:->id
LPD_PLCS_Schema:->id
LPD_PLCS_Schema:->version_id
The idea being that the user can enter a string and then specify to search
for the string in a particular complexType ...i.e the XPATH is built in real
time and the types are available to the user as a dropdown list.

Hmm, you may want to clarify what do you mean here :)
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3
Hi Again Oleg,

Thanks. I got this running. After sending the mail I was actually reading up
on the MS website and was just discovering the SOM...

Cheers
Rohit

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
Rohit Sharma wrote:
Then for each of them i need the attributes...like
Product : -> ID
Product: -> Product_Name
Product: -> description

and so on...
That's pretty easy. Learn about Schema object model (SOM) and
System.Xml.Schema namespace. The idea is to read schema file, compile it

into an object model, then for each complex type defined iterate over its declared attributes:
public class Class1 {
public static void Main(string[] args) {
XmlSchema schema = XmlSchema.Read(new
StreamReader("LPD_PLCS_Schema.xsd"),
new ValidationEventHandler(ShowCompileError));
schema.Compile(new ValidationEventHandler(ShowCompileError));
foreach (XmlSchemaType t in schema.SchemaTypes.Values) {
XmlSchemaComplexType type = t as XmlSchemaComplexType;
if (type != null) {
foreach (XmlSchemaAttribute attr in type.Attributes)
Console.WriteLine("{0}:->{1}", type.Name, attr.Name);

}
}
}
private static void ShowCompileError(object sender, ValidationEventArgs e) { Console.WriteLine("Validation Error: {0}", e.Message);
}

}

Note, that one cannot use xs:anySimpleType type directly in schema using ..NET. It's "implied" type, each simple type derives from by definition. So change <xs:element name="Value_component" type="xs:anySimpleType"/>
to
<xs:element name="Value_component"/>

With this change code above produces:
Unit:->id
System_breakdown:->id
Document_version:->id
Breakdown_element_realization:->id
Date_or_date_time_assignment:->id
System_element_version:->id
System_breakdown_context:->id
Part_view_definition:->id
View_definition_context:->id
Product:->id
PLCS_Part:->id
Document_assignment:->id
System_element:->id
Document:->id
Calendar_date:->id
Digital_file:->id
Next_assembly_usage:->id
Value_with_unit:->id
Identification_assignment:->id
Part_version:->id
Digital_document_definition:->id
System_element_usage:->id
System_breakdown_version:->id
System_element_definition:->id
LPD_PLCS_Schema:->id
LPD_PLCS_Schema:->version_id
The idea being that the user can enter a string and then specify to search for the string in a particular complexType ...i.e the XPATH is built in real time and the types are available to the user as a dropdown list.

Hmm, you may want to clarify what do you mean here :)
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by kamp | last post: by
1 post views Thread by suresh | last post: by
2 posts views Thread by Shailendra Batham | last post: by
4 posts views Thread by Mike Jansen | last post: by
4 posts views Thread by craig.wagner | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.