Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read this xml file in java (need to be done by using exported,firstName,lastName,...)?
    text
    copied!<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;objects xmlns="XXXXXXX"&gt; &lt;cuobject type-id="EmailSubscription" object-id="jjjil@gmail.com"&gt; &lt;object-attribute attribute-id="exported"&gt;true&lt;/object-attribute&gt; &lt;object-attribute attribute-id="firstName"&gt;jjj&lt;/object-attribute&gt; &lt;object-attribute attribute-id="lastName"&gt;jjj&lt;/object-attribute&gt; &lt;object-attribute attribute-id="subscribed"&gt;true&lt;/object-attribute&gt; &lt;/cuobject&gt; &lt;cuobject type-id="EmailSubscription" object-id="gggj@gmail.com"&gt; &lt;object-attribute attribute-id="exported"&gt;true&lt;/object-attribute&gt; &lt;object-attribute attribute-id="firstName"&gt;ghh&lt;/object-attribute&gt; &lt;object-attribute attribute-id="lastName"&gt;fhh&lt;/object-attribute&gt; &lt;object-attribute attribute-id="subscribed"&gt;true&lt;/object-attribute&gt; &lt;/cuobject&gt; &lt;cuobject type-id="EmailSubscription" object-id="mmm@gmail.com"&gt; &lt;object-attribute attribute-id="exported"&gt;true&lt;/object-attribute&gt; &lt;object-attribute attribute-id="firstName"&gt;mmm&lt;/object-attribute&gt; &lt;object-attribute attribute-id="lastName"&gt;mmm&lt;/object-attribute&gt; &lt;object-attribute attribute-id="subscribed"&gt;true&lt;/object-attribute&gt; &lt;/cuobject&gt; &lt;/objects&gt; </code></pre> <p>How to read this xml file in java (need to be done by using exported,firstName,lastName,...)? how do we do that? I am doing it like</p> <pre><code>NodeList nList = doc.getElementsByTagName("cuobject"); for (int temp = 0; temp &lt; nList.getLength(); temp++) { Node nNode = nList.item(temp); System.out.println("\nCurrent Element :" + nNode.getNodeName()); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String email = eElement.getAttribute("object-id"); String firstName = eElement. getElementsByTagName("object-attribute").item(1).getTextContent(); String lastName = eElement. getElementsByTagName("object-attribute").item(2).getTextContent(); String subscribed = eElement. getElementsByTagName("object-attribute").item(3).getTextContent(); } } </code></pre>
 

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