473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Traversing XSD

MMA
Hi there,
Is there a way to traverse an XSD using XPath. My research indicates no
conventional way of doing it, but I was wondering if there was a work around.
Thanks for your help and time.
Apr 3 '06 #1
11 2231


MMA wrote:
Is there a way to traverse an XSD using XPath. My research indicates no
conventional way of doing it, but I was wondering if there was a work around.


XSD is XML with namespaces so using XPath on an XSD document is
possible. If you need help with a particular XPath then let us know
details of the schema.

..NET also provides an XML Schema Object Model (SOM) which allows you to
extract type/element/attribute definitions of the schema in a structured
way, see
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconxsdschemaobjectmodelsom.asp>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 3 '06 #2
I'm not fully sure what you mean by traverse.

However, XML Schema is written in xml (intentionally) so you can
certainly evaluate XPath expressions against it:

eg.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns="http://Dickster.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" ="http://Dickster.com">

<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="surname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

e.g.
The XPath expression //xsd:element[@name='surname'] returns the
xsd:element node which has an attribute called 'name' set to
'surname'

Apr 3 '06 #3
XML Schema is written in xml (intentionally)
Therefore you can certainly evaluate XPath expressions against it:

eg.

<xsd:schema xmlns="http://Dickster.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Dickster.com">

<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="surname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

e.g.
The XPath expression //xsd:element[@name='surname'] returns the
xsd:element node which has an attribute called 'name' set to
'surname'

Apr 3 '06 #4
MMA
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:MIM="http://Dallas.Kodak.com/2005/Schema/MIMCORE"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.w3.org/1999/xhtml"
xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty"
xmlns:DICOM="http://Dallas.Kodak.com/2005/Schema/DICOM-in-XML"
targetNamespace="http://Dallas.Kodak.com/2005/Schema/MIMCORE"
version="2006Jan6">
<xs:element name="DeliveryJob">
<xs:complexType>
<xs:attribute name="version" type="xs:token" fixed="2006Feb23"
use="required" />
</xs:complexType>
</xs:element>
</xs:schema>

This is the XSD I am trying to navigate through and I am trying to access
the xs:attribute node to get the value of the name attribut. Dickester thanks
for your sample XPath query, do you think //xs:attribute/@name would work?

Thanks for your time and help
MMA

"dickster" wrote:
I'm not fully sure what you mean by traverse.

However, XML Schema is written in xml (intentionally) so you can
certainly evaluate XPath expressions against it:

eg.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsd:schema xmlns="http://Dickster.com"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" ="http://Dickster.com">

<xsd:element name="person">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="firstname" type="xsd:string"/>
<xsd:element name="surname" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>

e.g.
The XPath expression //xsd:element[@name='surname'] returns the
xsd:element node which has an attribute called 'name' set to
'surname'

Apr 3 '06 #5
When an XPath Expression is evaluated, it can return an object of one
of four types:
node-set
boolean
number
string

The return type of your xpath I believe is "string"

This XPath expression will search through the entire XML (i.e your XSD)
due to the "//" & return each matching string

So in english what I believe your Xpath will do is return the "value"
of each "name" attribute contained within an xs:attribute node

In your case this returns the string: "version"

For playing around with Xpath I cheat - Altova XMLSpy has a handy Xpath
evaluator

Hopefully someone will correct if what I have said is wrong.

Apr 3 '06 #6
Hi,
do you think //xs:attribute/@name would work?


Yes, it would. Try it and see ! It would return "version"

Regards,

Cerebrus.

Apr 3 '06 #7
A Question

Assuming MMA's xsd was

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:MIM="http://Dallas.Kodak.com/2005/Schema/MIMCORE"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://www.w3.org/1999/xhtml"
xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty"
xmlns:DICOM="http://Dallas.Kodak.com/2005/Schema/DICOM-in-XML"
targetNamespace="http://Dallas.Kodak.com/2005/Schema/MIMCORE"
version="2006Jan6">
<xs:element name="DeliveryJob">
<xs:complexType>
<xs:attribute name="version" type="xs:token" fixed="2006Feb23"
use="required">yyy</xs:attribute>
<xs:attribute name="Dickster"/>
</xs:complexType>
</xs:element>
</xs:schema>

would we say the Xpath expression "//xs:attribute/@name" returns

1. a string
2. a set of strings
3. a nodeset
4. other

Dickster

Apr 3 '06 #8


dickster wrote:

would we say the Xpath expression "//xs:attribute/@name" returns

1. a string
2. a set of strings
3. a nodeset
4. other


It selects a node set.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 3 '06 #9
had there just been one

<xs:attribute name="

node in the xml would the return have been "string" or "nodeset" again.

-----

obviously an xpath like: concat('George', ' ','Best') returns "string"

Apr 3 '06 #10


dickster wrote:
had there just been one

<xs:attribute name="

node in the xml would the return have been "string" or "nodeset" again.


It does not depend on the XML document what result type the XPath
expression has, that XPath expression
//xs:attribute/@name
selects a node set. Whether that node set is empty or contains one or
more attribute nodes depends on the XML document.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 3 '06 #11
Thanks Martin

Dickster

Apr 3 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: w.p. | last post by:
Hello! I want change default tab traversing in my app. But i don't know how to do it :( Belowe i include simple example - i want change default tab order: radiobutton "mode11" -> radiobutton...
2
by: Jim Cobban | last post by:
I am using Xerces to read an XML file and load it into a DOM so I can update it and subsequently serialize the updated DOM. The problem I have is that as I traverse the DOM I would like to inform...
3
by: Plamen Valtchev | last post by:
This is my problem: From JavaScript I want to find the list of all defined/loaded JavaScript functions/objects/names within the current scope (html page in a browser). the page could contain...
1
by: alfred | last post by:
Hi my question is on traversing a tree with DOM. how would I be able to traverse 2 trees at the same time. I have 2 XML documents, with similar nodes. I would like to traverse 1 xml document,...
0
by: thomson | last post by:
Hi all, can any one tell me which is fast traversing a XML file or a hash file is fast, i got few few field names and values in XML which i will use to retrieve. I can use Hash File also to do the...
2
by: thomson | last post by:
Hi all, can any one tell me which is fast traversing a XML file or a hash file is fast, i got few few field names and values in XML which i will use to retrieve. I can use Hash File also to do the...
11
hi
by: Ganga | last post by:
Can anybody tell me how to find out middle node of a link list without traversing all the nodes.
4
by: plmanikandan | last post by:
Hi, I am new to link list programming.I need to traverse from the end of link list.Is there any way to find the end of link list without traversing from start(i.e traversing from first to find the...
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: somcool | last post by:
I am facing an error while traversing a query in MS Access Details - When I click a button, a form which has the query opens up. There are certain fields which are in the form of combo box in the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.