Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Distinguish between empty string and no children, in XPath 2?

From: "Dimitre Novatchev" <dnovatchev@-----.--->
To: NULL
Date: 9/6/2008 9:49:00 PM


"Arndt Jonasson" <arndt.jonasson@g...> wrote in message 
news:3d8ef72b-e938-482d-9c1c-43583584331a@z......
>
> Let's say we have a schema (maybe expressed in XML Schema, but not
> necessarily so), that allows this instance document:
>
> <top>
>  <txt>This is text</txt>
>  <books>
>    <book>Tarzan</book>
>    <book>Harry Potter</book>
>  </books>
> </top>
>
> The text /top/txt may be empty, and the element /top/books may have no
> children, so this instance document is also allowed:
>
> <top>
>  <txt/>
>  <books/>
> </top>
>
> I now want to write an XPath expression that selects all nodes that do
> not have children in the schema. It would always select /top/txt and
> it would never select /top/books, even in the second example above.
>

This is possible in XPath 2.0 if the schema has separate types for all cases 
of element that must not have children-elements.

Then one can use the so called ElementTest, which is defined in the 
following way:

     ElementTest    ::=    "element" "(" (ElementNameOrWildcard ("," 
TypeName "?"?)?)? ")"


One of the possible XPath 2.0 expressions will be something like the 
following:

             //element(*,Type1) | //element(*,Type2) | ... | 
//element(*,TypeN)


where Type1, Type2, ..., typeN  are all the schema types that define 
elements that cannot have children-elements.

Probably substitution groups can be used so that all types above can be 
derived from a single abstract type, let's say "ChildlessElement".

Then the expression would be simply:

              //element(*,ChildlessElement)


Of course, to be able to evaluate such XPath 2.0 expressions one must have a 
full-blown XPath 2.0 implementation (either a Schema-Aware XSLT 2.0 
processor, or an XQuery processor)

For more information see the XPath 2.0 spec:

  http://www.w3.org/TR/xpath20/#doc-xpath-ElementTest

  http://www.w3.org/TR/xpath20/#id-element-test


Cheers,
Dimitre Novatchev











transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent