Author: mbenson Date: Mon Jul 23 12:27:46 2007 New Revision: 558838 URL: http://svn.apache.org/viewvc?view=rev&rev=558838 Log: [JXPATH-97] enable externally-registered namespaces on XML attributes
Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java?view=diff&rev=558838&r1=558837&r2=558838 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/dom/DOMAttributeIterator.java Mon Jul 23 12:27:46 2007 @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; @@ -108,7 +109,9 @@ String testNS = null; if (testPrefix != null) { - testNS = parent.getNamespaceURI(testPrefix); + NamespaceResolver nsr = parent.getNamespaceResolver(); + testNS = nsr == null ? null : nsr.getNamespaceURI(testPrefix); + testNS = testNS == null ? parent.getNamespaceURI(testPrefix) : testNS; } if (testNS != null) { Modified: jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java?view=diff&rev=558838&r1=558837&r2=558838 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/model/jdom/JDOMAttributeIterator.java Mon Jul 23 12:27:46 2007 @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.jxpath.ri.NamespaceResolver; import org.apache.commons.jxpath.ri.QName; import org.apache.commons.jxpath.ri.model.NodeIterator; import org.apache.commons.jxpath.ri.model.NodePointer; @@ -43,17 +44,26 @@ if (parent.getNode() instanceof Element) { Element element = (Element) parent.getNode(); String prefix = name.getPrefix(); - Namespace ns; + Namespace ns = null; if (prefix != null) { if (prefix.equals("xml")) { ns = Namespace.XML_NAMESPACE; } else { - ns = element.getNamespace(prefix); + NamespaceResolver nsr = parent.getNamespaceResolver(); + if (nsr != null) { + String uri = nsr.getNamespaceURI(prefix); + if (uri != null) { + ns = Namespace.getNamespace(prefix, uri); + } + } if (ns == null) { - // TBD: no attributes - attributes = Collections.EMPTY_LIST; - return; + ns = element.getNamespace(prefix); + if (ns == null) { + // TBD: no attributes + attributes = Collections.EMPTY_LIST; + return; + } } } } Modified: jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java?view=diff&rev=558838&r1=558837&r2=558838 ============================================================================== --- jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java (original) +++ jakarta/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java Mon Jul 23 12:27:46 2007 @@ -797,6 +797,15 @@ "count(vendor/product/rate:*)", new Double(2)); + assertXPathValue(context, + "vendor[1]/product[1]/rate:amount[1]/@rate:discount", "10%"); + assertXPathValue(context, + "vendor[1]/product[1]/rate:amount[1]/@price:discount", "10%"); + assertXPathValue(context, + "vendor[1]/product[1]/price:amount[1]/@rate:discount", "10%"); + assertXPathValue(context, + "vendor[1]/product[1]/price:amount[1]/@price:discount", "10%"); + // Preference for externally registered namespace prefix assertXPathValueAndPointer(context, "//product:name", --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]