diff --git a/src/reference/docbook/xml.xml b/src/reference/docbook/xml.xml index dab2b9df25..b0bfd2a3ae 100644 --- a/src/reference/docbook/xml.xml +++ b/src/reference/docbook/xml.xml @@ -187,7 +187,6 @@ All three options are mutially exlusive. Only one option can be set. - Below, please find several different usage examples on how to use XPath expressions using the XML namespace support including the various option for @@ -225,8 +224,91 @@ ]]> - - + +
+ Using XPath Expressions with Default Namespaces + + When working with default nanmespaces, you may run into situations that + behave differently than originally expected. Let's assume we have the + following XML document: + + + + + 0321200683 + 2 + + + 1590596439 + 1 + +]]> + + This document is not declaring any namespace. Therefore, applying + the following XPath Expression will work as expected: + + ]]> + + You might expect that the same expression will also work for the following + XML file. It looks exactly the same as the previous example but in addition + it also declares a default namespace: + + http://www.example.org/orders + + + + 0321200683 + 2 + + + 1590596439 + 1 + +]]> + + However, the XPath Expression used previously will fail in this case. + + + In order to solve this issue, you must provide a namespace prefix and + a namespace URI using either the ns-prefix + and ns-uri attibute or by providing a + namespace-map attribute instead. The namespace + URI must match the namespace declared in your XML document, which in + this example is http://www.example.org/orders. + + + The namespace prefix, however, can be arbitrarily chosen. In fact, just + providing an empty String will actually work (Null is not allowed). In the + case of a namespace prefix consisting of an empty String, your Xpath + Expression will use a colon (":") to indicate the default namespace. + If you leave the colon off, the XPath expression will not match. The following + XPath Expression will match agains the XML document above: + + ]]> + + Of course you can also provide any other arbitrarily chosen namespace prefix. + The following XPath expression using the myorder + namespace prefix will match also: + + ]]> + + It is important to remember that the namespace URI is the really important + piece of information to declare, not the prefix itself. The + Jaxen FAQ + summarizes the point very well: + + + + In XPath 1.0, all unprefixed names are unqualified. There is no + requirement that the prefixes used in the XPath expression are + the same as the prefixes used in the document being queried. + Only the namespace URIs need to match, not the prefixes. + + +
+
Transforming XML Payloads