How to use XPath with Namespaces in the xml ?


XML & Web services: How to use XPath with Namespaces in the xml ?

  1. Hi all,
    I need to reference a certain Node in a Document using XPath notation.
    The problem is the the XML Document contains Namespaces inside it

    <xn:SubNetwork id="JRANM">
        <xn:VsDataContainer id="1">
    </xn:SubNetwork >

    Using DOMXPath (from weblogic.xml.xpath)

      DOMXPath xPath = new DOMXPath("xn:SubNetwork/*");
      Set nodeset = xPath.evaluateAsNodesetthis.xmlRootElement);

    When I Iterate through the Set I can see it's empty.
    (On the other hand without namespaces everything is fine.)

    So how can I reference a Node that contains a namespace in it ?
    Thanks a lot
  2. I haven't used DOMXPath but some xpath libraries require that you explicitly set the namespaces even though they are in the xml file. The .net stuff requires this, dom4j does not.

    - dave