title: JAVA XML : get content Node
body: <p>I have an xml like this :</p>
  
  <pre><code>&lt;root&gt;
     &lt;countries&gt;
        &lt;country id="98" nom="Espagne"/&gt;
        &lt;country id="76" nom="France"/&gt;
     &lt;/countries&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I can read inside root tag with this :</p>
  
  <pre><code>Document doc = DocumentBuilderFactory.newInstance()
                      .newDocumentBuilder().parse(XmlFile);
  
  System.out.println("Root element :" + doc.getDocumentElement().getNodeName());      
  
  Node NodeCountries = doc.getElementsByTagName("countries").item(0);     
  
  System.out.println(nodeToString(NodeCountries));
  
  
  private static String nodeToString(Node node) throws Exception{
              StringWriter sw = new StringWriter();
  
                Transformer t = TransformerFactory.newInstance().newTransformer();
                t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                t.transform(new DOMSource(node), new StreamResult(sw));
  
              return sw.toString();
            }
  </code></pre>
  
  <p>But I can not get all content inside countries tag like this :</p>
  
  <pre><code>&lt;country id="98" nom="Espagne"/&gt;
  &lt;country id="76" nom="France"/&gt;
  </code></pre>