Download Intel(R) XML Software Suite 1.2 for Java* Environments User's Guide
Transcript
XSSUserGuideForJava
Resolving External Resources
When the evaluated XPath expression references a variable or external function or
contains a namespace prefix, the XPath evaluation process depends on resolvers set
by the calling application. Before compiling and evaluating an XPath expression, the
application uses relative methods to set the correct resolver and context. The variable
resolver and function resolver can be set as properties of XPathFactory and XPath
objects, and the namespace context can only be set as a property of XPath.
Namespace Context
When namespace prefixes are used in an XPath expression, the prefixes need to be
resolved to URI addresses. The mapping of a namespace prefix to URI is provided by
an object implementing the javax.xml.namespace.NamespaceContext interface.
You can set your derived javax.xml.namespace.NamespaceContext objects to
XPath objects by calling the XPath.setNamespaceContext() method.
You need to implement one of the following methods:
•
java.lang.String getNamespaceURI(java.lang.String prefix)
•
java.lang.String getPrefix(java.lang.String namespaceURI)
•
java.util.Iterator getPrefixes(java.lang.String
namespaceURI)
The User-defined Namespace Context example demonstrates setting the namespace
prefix mapping through the getNamespaceURI() method.
User-defined Namespace Context
public class MyNamespaceContext implements NamespaceContext
{
public String getNamespaceURI(String prefix)
{
if (prefix.equals("user"))
return "http://user.com";
else
return null;
}
public String getPrefix(String namespace)
{
if (namespace.equals("http://user.com"))
return "user";
else
58