Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
 
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
Edited 12-Feb-13 11:06am
v2
Comments
Sandeep Mewara at 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 at 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:
Member 9740382 at 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:
" "
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
good
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", "http://www.w3.org/2001/XMLSchema");
4) dirty xpath to get all xs:elements with type attributes set is:
 
//xs:element[@type]
 

http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectnodes.aspx[^]
 
http://msdn.microsoft.com/ru-ru/library/system.xml.xmlnamespacemanager.addnamespace(v=vs.95).aspx[^]
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 320
2 OriginalGriff 255
3 Vinay Mistry 168
4 Jared Sanow 145
0 Sergey Alexandrovich Kryukov 5,939
1 OriginalGriff 4,885
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2014
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