Adds support for unqualified namespaced XML content (#1590)
Adds support for unqualified namespaced XML content and fixes how qualified namespace URIs values are retrieved. Fixes gh-1571
This commit is contained in:
@@ -1843,6 +1843,54 @@ public void validate_xmlMatches() throws Exception {
|
||||
----
|
||||
====
|
||||
|
||||
==== XML Support for Namespaces
|
||||
Namespaced XML is supported. However, any XPath expresssions used to select namespaced content must be updated.
|
||||
|
||||
Consider the following explicitly namespaced XML document:
|
||||
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<ns1:customer xmlns:ns1="http://demo.com/customer">
|
||||
<email>customer@test.com</email>
|
||||
</ns1:customer>
|
||||
----
|
||||
The XPath expression to select the email address is: `/ns1:customer/email/text()`.
|
||||
|
||||
WARNING: Beware as the unqualified expression (`/customer/email/text()`) results in `""`.
|
||||
|
||||
For content that uses an unqualified namespace, the expression is more verbose. Consider the following XML document that
|
||||
uses an unqualified namespace:
|
||||
|
||||
[source,xml,indent=0]
|
||||
----
|
||||
<customer xmlns="http://demo.com/customer">
|
||||
<email>customer@test.com</email>
|
||||
</customer>
|
||||
----
|
||||
The XPath expression to select the email address is
|
||||
```
|
||||
*/[local-name()='customer' and namespace-uri()='http://demo.com/customer']/*[local-name()='email']/text()
|
||||
```
|
||||
WARNING: Beware, as the unqualified expressions (`/customer/email/text()` or `*/[local-name()='customer' and namespace-uri()='http://demo.com/customer']/email/text()`)
|
||||
result in `""`. Even the child elements have to be referenced with the `local-name` syntax.
|
||||
|
||||
====== General Namespaced Node Expression Syntax
|
||||
- Node using qualified namespace:
|
||||
```
|
||||
/<node-name>
|
||||
```
|
||||
- Node using and defining an unqualified namespace:
|
||||
```
|
||||
/*[local-name=()='<node-name>' and namespace-uri=()='<namespace-uri>']
|
||||
```
|
||||
NOTE: In some cases, you can omit the `namespace_uri` portion, but doing so may lead to ambiguity.
|
||||
|
||||
- Node using an unqualified namespace (one of its ancestor's defines the xmlns attribute):
|
||||
```
|
||||
/*[local-name=()='<node-name>']
|
||||
```
|
||||
|
||||
|
||||
[[contract-dsl-multiple]]
|
||||
=== Multiple Contracts in One File
|
||||
|
||||
|
||||
Reference in New Issue
Block a user