简体   繁体   中英

Xpointer: is it possible to select an empty node-set?

Question

I have an XInclude that includes a node-set resulting from the specified xpointer attribute's expression.

Is it possible to select, with the xpointer , an empty node-set, so to not include anything?


Issue

The reason is that my xincluded & xpointed node could exist and could NOT exist; so I'm getting a:

XInclude error : XPointer evaluation failed

in the case the pointed node does not exist.


Example

The expression is something like:

    xmlns(ns=urn:my:namespace)
    xpointer(/ns:element1/*[ns:elementA | ns:elementB])

I would like to change the XPointer so that the XInclude does NOT include anything ( without raising the error ) in the case the node is not found.

Something like:

    xmlns(ns=urn:my:namespace)
    xpointer(/ns:element1/*[ns:elementA | ns:elementB | NOT_FOUND_NODES ])

Is there any way to accomplish that?

Did you try to use xi:fallback instruction ?

For example, if you instruct this

<xi:include href="somedoc.xml" xpointer="xmlns(ns=urn:my:namespace)xpointer(/ns:element1/*[ns:elementA | ns:elementB])" />

and xpointer resource doesn't exists you will get a resource error (as express in xpointer specification). To avoid this, you can use fallback:

<xi:include href="somedoc.xml" xpointer="xmlns(ns=urn:my:namespace)xpointer(/ns:element1/*[ns:elementA | ns:elementB])">
   <xi:fallback><NOT_FOUND_NODES/></xi:fallback>
</xi:include>

so when xpointer will fall in resource error, fallback will insert NOT_FOUND_NODES element

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM