When running tests which are based on XML or XPath, namespaces which are declared
with a prefix are detected automatically. Because the XML standard allows to
declare namespaces multiple times, PDFUnit does not detect the default namespace.
It has to be set using the attribute defaultNamespace=".."
:
<!-- The default namespace has to be declared, but any alias can be used for it. --> <testcase name="hasXFAData_UsingDefaultNamespace"> <assertThat testDocument="xfa/xfa-enabled.pdf"> <hasXFAData> <withNode tag="foo:log/foo:to" value="memory" defaultNamespace="http://www.xfa.org/schema/xci/2.6/" /> </hasXFAData> </assertThat> </testcase>
Note that there are two prefixes used for the same namespace, first
foo
and then bar
. That seems strange, but
the Java Standard requires an arbitrary prefix, which must not be omitted.
The next example shows the usage of a default namespace for the tag
<matchingXPath />
:
<testcase name="hasXMPData_MatchingXPath_WithDefaultNamespace"> <assertThat testDocument="xmp/metadata-added.pdf"> <hasXMPData> <matchingXPath expr="//foo:format = 'application/pdf'" defaultNamespace="http://purl.org/dc/elements/1.1/" /> </hasXMPData> </assertThat> </testcase>