Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to scroll a list of tags from the first to the last using XPATH?
    text
    copied!<p>I am absolutly new in <strong>XML Parsing</strong> and in <strong>XPATH query</strong> in Java and I have the following problem:</p> <p>I have the following XML file on which I have to do some queries:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;root&gt; &lt;status&gt; &lt;id&gt;0&lt;/id&gt; &lt;message /&gt; &lt;/status&gt; &lt;objectList&gt; &lt;object id="obj1"&gt; &lt;property1&gt;value&lt;/property1&gt; &lt;property2&gt;value&lt;/property2&gt; &lt;property3 /&gt; &lt;/object&gt; &lt;object id="obj2 "&gt; &lt;property1&gt;value&lt;/sproperty1&gt; &lt;property2&gt;value&lt;/property2&gt; &lt;property3&gt;value&lt;/property3&gt; &lt;/object&gt; &lt;object id="obj3 "&gt; &lt;property1&gt;value&lt;/sproperty1&gt; &lt;property2&gt;value&lt;/property2&gt; &lt;property3&gt;value&lt;/property3&gt; &lt;/object&gt; &lt;/objectList&gt; &lt;/root&gt; </code></pre> <p>The first thing that I have to do is take the value inside the unique <strong><code>&lt;id&gt;0&lt;/id&gt;</code></strong> tag and I have do it using the following XPATH query (and this query work well):</p> <pre><code>XPath xPath = XPath.newInstance("s:Envelope/s:Body"); xPath.addNamespace("s", "http://schemas.xmlsoap.org/soap/envelope/"); org.jdom.Element objectElement = (Element) xPath.selectSingleNode(documentXML); System.out.println("objectElement: " + objectElement); </code></pre> <p>(where <strong>documentXML</strong> contains the previous XML document)</p> <p>This work well and put inside my <strong>objectElement</strong> object the value 0 that is inside the <strong><code>&lt;id&gt;0&lt;/id&gt;</code></strong> tag.</p> <p>Ok, now I have to perform a more complex operation (and I have no many ideas about how do it) that is the following one:</p> <p>As you can see I have a tag named <strong>objectList</strong> that contains 3 tag named <strong>object</strong> that represent a list of 3 Java objects having some some properties (<strong>property1</strong>, <strong>property2</strong> and <strong>property3</strong> that will be 3 variables into the related Java objectt)</p> <p>Now I have to perform the following operations: <strong>for each object tag inside the XML document create a new Java object and put the property subtag value inside the related value in the new Java object</strong></p> <p>The problem is that I have no idea about scroll through the list of obecjt tags that areinside my tag (from the first to the last)</p> <p>Some idea? Someone can help me to do it?</p> <p>Tnx</p> <p>Andrea</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload