How to Parse XML Data <p>I am having an XML,which is like</p> <pre><code>&lt;polygon&gt; &lt;coordinates&gt; &lt;coordinate order="1" long="75.9375" lat="32.91648534731439"/&gt; &lt;coordinate order="2" long="76.640625" lat="23.241346102386135"/&gt; &lt;coordinate order="3" long="88.59375" lat="31.052933985705163"/&gt; &lt;/coordinates&gt; &lt;/polygon&gt; </code></pre> <p>I want to get the long and lat values of every coordinates and assign to string. I was trying like :</p> <pre><code>DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse( new InputSource(new StringReader(s))); System.out.println(document.getChildNodes()); NodeList nl = document.getElementsByTagName("coordinates"); for (int i = 0; i &lt; nl.getLength(); i++) { System.out.println("name is : "+nl.item(i).getNodeName()); System.out.println("name is : "+nl.item(i).getNodeValue()); } </code></pre> <p>The String reader is the XML String I pass,but I am not able to get the data.</p>