3 Replies Latest reply on Mar 13, 2007 7:48 PM by DrClap

    XPath to xsd:element??

      Hello all:

      I'd like to use XPath to get all the nodes below that have the following tag "xsd:element ". Currently, I am using:
      List nodes = doc.selectNodes("//xsd:element");
      It returns a list with 0 elements. Why? Is it possible to use XPath with xsd tags? (It works when I use simple tags)

      Thanks in advance

      Here is a snippet of the xml.
      <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
      <xsd:element name="CATALOG_NAME" type="xsd:string" sql:field="CATALOG_NAME" minOccurs="0"/>
      <xsd:element name="SCHEMA_NAME" type="xsd:string" sql:field="SCHEMA_NAME" minOccurs="0"/>
      <xsd:element name="CUBE_NAME" type="xsd:string" sql:field="CUBE_NAME" minOccurs="0"/>
      <xsd:element name="SET_NAME" type="xsd:string" sql:field="SET_NAME" minOccurs="0"/>
      <xsd:element name="SCOPE" type="xsd:int" sql:field="SCOPE"/>
      <xsd:element name="DESCRIPTION" type="xsd:string" sql:field="DESCRIPTION" minOccurs="0"/>
      <xsd:element name="EXPRESSION" type="xsd:string" sql:field="EXPRESSION" minOccurs="0"/>
      <xsd:element name="DIMENSIONS" type="xsd:string" sql:field="DIMENSIONS" minOccurs="0"/>
        • 1. Re: XPath to xsd:element??
          You need to specify the namespace context somewhere before you execute that line of code. Remember that when you use namespaces, the prefix is just a short cut that identifies the actual namespace URI, and you always have to tell the processing software how to map the prefix to the namespace URI.

          In a full XML document you declare it like this:
          but in an XPath expression you have to declare it in some other way. Look for methods that create namespace context and apply it to XPath somehow.
          • 2. Re: XPath to xsd:element??
            Within the XML, there is the following. Could this be declaring the "xsd" namespace?
            <root xmlns="urn:schemas-microsoft-com:xml-analysis:rowset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            How can I set the namespace of the XPath in a org.dom4j document?
            • 3. Re: XPath to xsd:element??
              Yes, that's right. (I should have said xmlns:xsd in my earlier post, not xml:xsd.)

              I have no experience with dom4j so I have no idea how it handles XPath versus namespaces. And I didn't see anything special in my 5 minutes of reading the API documentation. Does it have a support forum? If so, ask there.