Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XPath expression for fetching element names & attributes

843834Sep 24 2004 — edited Sep 24 2004
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 22 2004
Added on Sep 24 2004
1 comment
499 views