In XPath, there is no such thing as a 'default namespace'. The empty prefix always resolves to the empty namespace URI.
170171172173174175176177178179180
Object contextNode = contextNodeSet.get(0); if (namedAccess) { // get the iterator over the nodes and check it String uri = null; if (hasPrefix) { uri = support.translateNamespacePrefixToUri(prefix); if (uri == null) { throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix); } } Iterator axisNodeIter = iterableAxis.namedAccessIterator(
222223224225226227228229230231232
List newNodeSet = new ArrayList(contextSize); if (namedAccess) { String uri = null; if (hasPrefix) { uri = support.translateNamespacePrefixToUri(prefix); if (uri == null) { throw new UnresolvableException("XPath expression uses unbound namespace prefix " + prefix); } } for (int i = 0; i < contextSize; ++i) {
6970717273747576777879
"http://cheese.org"); xpath.addNamespace("squeeze", "http://squeeze.org"); NamespaceContext nsContext = xpath.getNamespaceContext(); assertEquals( "http://cheese.org", nsContext.translateNamespacePrefixToUri( "cheese" ) ); assertEquals( "http://squeeze.org", nsContext.translateNamespacePrefixToUri( "squeeze" ) ); }
71727374757677787980
"http://squeeze.org"); NamespaceContext nsContext = xpath.getNamespaceContext(); assertEquals( "http://cheese.org", nsContext.translateNamespacePrefixToUri( "cheese" ) ); assertEquals( "http://squeeze.org", nsContext.translateNamespacePrefixToUri( "squeeze" ) ); } }
8990919293949596979899
*/ public void testMapCopy() { Map map = new HashMap(); SimpleNamespaceContext context = new SimpleNamespaceContext(map); map.put("pre", "http://www.example.org/"); assertNull(context.translateNamespacePrefixToUri("pre")); } public void testCantUseNonStringsAsValues() { Map map = new HashMap(); map.put("key", new Object());
126127128129130131132133134135136
Document doc = builder.newDocument(); Element root = doc.createElementNS("http://www.example.org/", "pre:root"); doc.appendChild(root); context.addElementNamespaces(new org.jaxen.dom.DocumentNavigator(), root); assertEquals("http://www.example.org/", context.translateNamespacePrefixToUri("pre")); } public void testSerialization() throws IOException, ClassNotFoundException { // construct test object
150151152153154155156157158159160
ObjectInputStream ois = new ObjectInputStream(in); Object o = ois.readObject(); SimpleNamespaceContext copy = (SimpleNamespaceContext) o; // test the result assertEquals("http://www.a.com", copy.translateNamespacePrefixToUri("a")); assertEquals("http://www.b.com", copy.translateNamespacePrefixToUri("b")); assertEquals("", ""); }
151152153154155156157158159160161
Object o = ois.readObject(); SimpleNamespaceContext copy = (SimpleNamespaceContext) o; // test the result assertEquals("http://www.a.com", copy.translateNamespacePrefixToUri("a")); assertEquals("http://www.b.com", copy.translateNamespacePrefixToUri("b")); assertEquals("", ""); } }