Solved

XPath and XSD

Posted on 2006-11-01
5
2,038 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 30

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 30

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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