Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Using //

From: "JS" <sss@---.--->
To: NULL
Date: 6/16/2009 12:45:00 PM
I have this XML file:

<root>
  <lines>
    <line order="0">
       <content id="A" value="0_A"/>
       <content id="B" value="0_B"/>
       <content id="C" value="0_C"/>
       <content id="D" value="0_D"/>
       <content id="E" value="0_E"/>
     </line>
     <line order="1">
       <content id="A" value="1_A"/>
       <content id="B" value="1_B"/>
       <content id="C" value="1_C"/>
       <content id="D" value="1_D"/>
       <content id="E" value="1_E"/>
     </line>
   </lines>
</root>


From Java I am trying to print values for all elements where ID = "A":

  public void test(){
    javax.xml.xpath.XPathFactory factory = 
javax.xml.xpath.XPathFactory.newInstance();
    javax.xml.xpath.XPath xpath = factory.newXPath();
    javax.xml.xpath.XPathExpression expression;
    String result;
    try {
      expression = xpath.compile("//content[@id =\"A\"]/@value");
      URL url = this.getClass().getClassLoader().getResource("test.xml");
      String path = url.toURI().getPath();
      result = expression.evaluate(new org.xml.sax.InputSource(path));
      System.out.println("result is = " + result);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }


But only:

0_A

is printed. Does "//" not mean that all 'content' elements are chosen? 



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent