[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XPath and XSD

Posted on 2006-11-01
5
Medium Priority
?
2,064 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 1200 total points
ID: 17853882
0
 
LVL 13

Assisted Solution

by:joechina
joechina earned 800 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

834 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