Click here to Skip to main content
13,150,867 members (46,641 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I've learned a lot about XSD and XML from your site. Thanks for all the information that you put there. I have a question below.

I've searched a lot of sites and pages and could not find a way to accomplish the below.

I am writing a C# program and in the program I need to read an XSD file and get the "type=" value for each element. For example I might have an element such as below:

<xs:element name="Amount" minoccurs="0" maxoccurs="1" type="xs:date" xmlns:xs="#unknown">

I'd like to get the "xs:date" to save in a string variable. I can traverse the XSD file and get all element names but I simply cannot find a way to get to the type.

Can you please provide some help?

Thank You!
Posted 12-Feb-13 7:36am
Updated 12-Feb-13 11:06am
Sandeep Mewara 12-Feb-13 14:22pm
Are you directing this question to someone specific? We are missing the context and not too sure what exactly you are referring to... an article?
Member 9740382 12-Feb-13 15:44pm
If anyone knows the answer, please post. Much appreciation! Here is what I am trying to do. In my XSD file I have several elements and one is:
<xs:element name="Amount" minOccurs="0" maxOccurs="1" type="xs:unsignedLong"

I already figured a way to read the entire XSD file to get the element names but I cannot get at the type of the element.

I would like to use C# to extract the type of "xs:unsignedLong" into a string variable.

Thanks again.
Member 9740382 13-Feb-13 9:02am
Thanks for your reply! I already have a way of reading the schema and getting at all elements. The one thing I am looking to do is to extract the element type. For example I have a line below:
" <xs:element name="Quantity" minOccurs="0" maxOccurs="1" type="xs:integer" /> "
I know how to read the above to get the name, minOccurs, and maxOccurs. What I don't know is how to get the type. I'd like to read the element type to return 'xs:integer'.
Any help would be greatly appreciated!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

key points are:

1) XSD file itself xml document.

2) xml files can be queried with xpath - in C# it could be done with SelectNodes method of xml doc.
SelectNodes("//somenode", nsmgr);

3)As you see SelectNodes has nsmgr parameter. (XmlNamespaceManager nsmgr)
If you want to query xsd which is in xs: namespace, you have to add it:

nsmgr.AddNamespace("xs", "");

4) dirty xpath to get all xs:elements with type attributes set is:


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170924.2 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100