Solved

XPath and XSD

Posted on 2006-11-01
5
2,020 Views
Last Modified: 2013-11-19
I have an XML file in a treeview and I can get the XPATH of the node for every treenode. I want to traverse my XSD (on which this XML is based on) and show all the attributes this node has according to the XSD.

How can I navigate to the element in the XSD from the XPATH? XSD has all the elements as:

<xs:Element name="whatever">

Can XPath get to the "names"?
0
Comment
Question by:srinivas_vemla
  • 2
  • 2
5 Comments
 

Author Comment

by:srinivas_vemla
ID: 17852639
Any ideas pls...
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 17853062
I believe  it can :)
If you want to select ALL "names" you use something like this:

//Element[@name]

'@' points to attributes.

See http://www.w3schools.com/xpath/xpath_syntax.asp


0
 

Author Comment

by:srinivas_vemla
ID: 17853263
Are we talking of using the XpathNavigator or something?... what would a sample C# code be?
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 300 total points
ID: 17853882
0
 
LVL 13

Assisted Solution

by:joechina
joechina earned 200 total points
ID: 17858579
Here is what I have, not sure if it is what you want:

XPathDocument x = new XPathDocument("test.xsd");
XPathNavigator nav = x.CreateNavigator();
XmlNamespaceManager mngr = new XmlNamespaceManager(nav.NameTable);
mngr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
XPathNavigator resultNav = nav.SelectSingleNode("//xs:element",mngr);
string result = resultNav.GetAttribute("name", "");

result is MyElement

test.xsd is

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="test" targetNamespace="http://tempuri.org/test.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/test.xsd" xmlns:mstns="http://tempuri.org/test.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="MyElement">
    <xs:complexType>
      <xs:sequence />
    </xs:complexType>
  </xs:element>
</xs:schema>
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now