Most XPath implementations solve this problem by registering a namespace URI with an arbitrary prefix in the host language, but I don't see any information related to this in XMLSearch docs (and Google doesn't help much either).
The next time you should help as follows:
//*[local-name()='Image']
This selects image elements from any (or not) namespace.
Or more specifically (as shown in @Shawn's answer):
//*[local-name()='Image' and namespace-uri()='http://fedex.com/ws/ship/v9']
Note, however, that this would not be necessary at all, given some way to register the namespace using the XPath mechanism. For example, consider this complete Java example:
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse("workbook.xml"); XPath xpath = XPathFactory.newInstance().newXPath(); NamespaceContext ctx = new NamespaceContext() { public String getNamespaceURI(String prefix) { if ("myName".equals(prefix)) { return "http://fedex.com/ws/ship/v9"; } return null; } public String getPrefix(String uri) { throw new UnsupportedOperationException(); } public Iterator getPrefixes(String uri) { throw new UnsupportedOperationException(); } }; xpath.setNamespaceContext(ctx); XPathExpression expr = xpath.compile("//myName:Image"); NodeList nodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { System.out.println("[" + nodes.item(i).getTextContent() + "]"); }
Conclusion:
[HUGE STUFF!!!]
This code associates the myName prefix with the namespace URI http://fedex.com/ws/ship/v9 . The following expressions can refer to nodes in this namespace using an arbitrary prefix name:
It can be assumed that ColdFusion supports similar functions, but I could not find it in the documents. However, if such a function does not exist, then this is a limitation of ColdFusion. In particular, it has nothing to do with XPath itself or where the namespace declaration appears in the original document.
source share