Solved

XPath and XSD

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular - break the dataset in chunks? 7 50
SQL Login 17 48
ASP.NET 5 Templates 2 77
Release Dynamically Allocated Memory in C# 3 19
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…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

813 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

16 Experts available now in Live!

Get 1:1 Help Now