DOM4J xpath-select colon node with namespace <p>Given the xml content is as below;</p> <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;&lt;s:Body&gt;&lt;CreateResponse xmlns="http://gtestserver/"&gt;&lt;CustomerId&gt;8124138&lt;/CustomerId&gt;&lt;InternalResponseCode&gt;Success&lt;/InternalResponseCode&gt;&lt;ResponseCode&gt;0&lt;/ResponseCode&gt;&lt;ResponseDate&gt;2016-08-31T07:57:22.7760577Z&lt;/ResponseDate&gt;&lt;ResponseDescription&gt;Success&lt;/ResponseDescription&gt;&lt;UserId&gt;7424876375&lt;/UserId&gt;&lt;/CreateResponse&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt; </code></pre> <p>I need to pickup the node :<strong>CustomerId</strong> ,but i cannot get it correctly ,the code i used here:</p> <pre><code> Document document = new SAXReader().read(new ByteArrayInputStream(xmlfile.getBytes("UTF-8"))); Node foundnode = null; Element rootElement = document.getRootElement(); String namespace = rootElement.getNamespaceURI(); if (namespace != null) { DefaultXPath defaultXPath = new DefaultXPath(xpath); Map&lt;String, String&gt; namespaces = new TreeMap&lt;String, String&gt;(); namespaces.put("ns", namespace); defaultXPath.setNamespaceURIs(namespaces); } foundnode = document.selectSingleNode("/ns:s:Envelope/ns:s:Body/ns:CreateResponse/ns:CustomerId"); </code></pre> <p>Then it throws below exception :</p> <pre><code>org.dom4j.InvalidXPathException: Invalid XPath expression: /ns:s:Envelope/ns:s:Body/ns:CreateResponse/ns:CustomerId Unexpected ':' at org.dom4j.xpath.DefaultXPath.parse(DefaultXPath.java:360) at org.dom4j.xpath.DefaultXPath.&lt;init&gt;(DefaultXPath.java:59) at com.github.becauseQA.xml.DOM4JUtils.getNodes(DOM4JUtils.java:152) at </code></pre> <p>I know it caused by the xpath used here ,but i don't know which xpath should i pickup here, you can see the node has : ,so when use the namespace with ns: for each node ,it cannot parse it . Anyone know how to pickup the node with namespace and special character in the node name ? thanks .</p>