Skip to content
Stefan Bodewig edited this page Jan 8, 2016 · 1 revision

NamespaceContext

NamespaceContext sounds a lot more complex that it really is. As far as XMLUnit is concerned it is a simple map (or dictionary) that maps from XML namespace prefixes to namespace URIs.

The namespace context is mostly used together with XPath expressions. While XML documents define the mapping of prefixes to URIs themselves, there is no such mechanism for XPath selectors. By default XPath selectors use local names only, if you want to use prefixes inside of selectors, you need to specify the mapping explicitly.

JAXP uses the javax.xml.namespace.NamespaceContext class for the mapping, .NET uses XmlNamespaceManager. XMLUnit unifies and simplifies their APIs as a simple map.

XMLUnit uses the NamespaceContext for XPathEngine and in the context of the DifferenceEngine - differences are associated with XPath selectors identifying the different nodes and this selector will use prefixes defined in the NamespaceContext if given (otherwise it will only use local names).