XPath expression for fetching element names & attributes
843834Sep 24 2004 — edited Sep 24 2004Hi out there!
I�m trying to get a result set out of a xml schema, using XPath. The problem is, that any expression gets just a whole node set back, as it seems. The result I�d like to get would be the following. Imagine I got a schema like this:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:r="http://recipes.org"
targetNamespace="http://recipes.org"
elementFormDefault="qualified">
<element name="recipe">
<complexType>
<sequence>
<element name="title" type="string"/>
<element ref="r:ingredient" minOccurs="0" maxOccurs="unbounded"/>
<element ref="r:preparation"/>
<element name="comment" minOccurs="0" type="string"/>
<element name="nutrition">
<complexType>
<attribute name="protein" type="r:nonNegativeDecimal" use="required"/>
<attribute name="carbohydrates" type="r:nonNegativeDecimal" use="required"/>
<attribute name="fat" type="r:nonNegativeDecimal" use="required"/>
<attribute name="calories" type="r:nonNegativeDecimal" use="required"/>
<attribute name="alcohol" type="r:nonNegativeDecimal" use="optional"/>
</complexType>
</element>
</sequence>
</complexType>
</element>
</schema>
Now, when I`m refering to the element <attribute name="protein" type="r:nonNegativeDecimal" use="required"/>, I would like to get all ancestors of it, which is not a big issue at all, but i`d just like to get their names and attributes, if they have some. So the result should be something like:
<element name="recipe">
<complexType>
<sequence>
<element name="nutrition">
<complexType>
</complexType>
</element>
</sequence>
</complexType>
</element>
Any ideas anybody?
Thanks in advance, Jens