Solved

XPath and XSD

Posted on 2006-11-01
5
2,046 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to count occurrences of each item in an array.
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 …

705 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