title: Parsing XML with XmlUtils
body: <p>I am using <code>XmlUtils</code> to parse and extract the values of the <code>id</code> attribute in a List but it returns empty.</p>
  
  <p>Where am I going wrong ? Please suggest</p>
  
  <h2>XML:</h2>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;address-book xmlns="qwerty" xmlns:ab2="asdfgh"&gt;
  &lt;contact time-stamp="2014-02-26T16:35:20.678+02:00" id="12345"&gt;
      &lt;ns2:person-details index="9AmmUzHXBPsK:96"&gt;
          &lt;ns2:name index="1"&gt;
              &lt;ns2:name-entry index="1"&gt;
                  &lt;ns2:display-name&gt;DISP0dNXoq&lt;/ns2:display-name&gt;
                  &lt;ns2:given display-order="1"&gt;GIVENw17JCb&lt;/ns2:given&gt;
                  &lt;ns2:family display-order="1"&gt;FAMILYcl7h2y&lt;/ns2:family&gt;
              &lt;/ns2:name-entry&gt;
          &lt;/ns2:name&gt;
          &lt;ns2:comm-addr xml:lang="en"&gt;
              &lt;ns2:uri-entry addr-uri-type="trn" index="1:1111"&gt;
                  &lt;ns2:addr-uri&gt;cnaFC@hOog6.com&lt;/ns2:addr-uri&gt;
                  &lt;ns2:label xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt;
              &lt;/ns2:uri-entry&gt;
              &lt;ns2:tel tel-type="Home" index="2:22222"&gt;
                  &lt;ns2:tel-nb&gt;
                      &lt;ns2:tel-str&gt;97235852622&lt;/ns2:tel-str&gt;
                  &lt;/ns2:tel-nb&gt;
              &lt;/ns2:tel&gt;
              &lt;ns2:tel tel-type="Work" index="3:33333"&gt;
                  &lt;ns2:tel-nb&gt;
                      &lt;ns2:tel-str&gt;97230557837&lt;/ns2:tel-str&gt;
                  &lt;/ns2:tel-nb&gt;
              &lt;/ns2:tel&gt;
              &lt;ns2:tel tel-type="Mobile" index="3:33333"&gt;
                  &lt;ns2:tel-nb&gt;
                      &lt;ns2:tel-str&gt;972542993697&lt;/ns2:tel-str&gt;
                  &lt;/ns2:tel-nb&gt;
              &lt;/ns2:tel&gt;
          &lt;/ns2:comm-addr&gt;
      &lt;/ns2:person-details&gt;
      &lt;contact-status&gt;
          &lt;contact-source&gt;contact-source-sim-1393425320678&lt;/contact-source&gt;
      &lt;/contact-status&gt;
  &lt;/contact&gt;
  &lt;contact time-stamp="2014-02-26T16:37:19.370+02:00" id="12346"&gt;
  &lt;contact time-stamp="2014-02-26T16:38:53.345+02:00" id="12347"&gt;
  &lt;contact time-stamp="2014-02-26T16:37:30.828+02:00" id="12348"&gt;
  </code></pre>
  
  <h2>Code:</h2>
  
  <pre><code>Document document = XmlUtils.createDocument(responseString);
  List&lt;Element&gt; list = document.getRootElement().getChildren("address-book");
  for( Element ele : list){
      System.out.println(ele.getChild("contact").getAttribute("id").getValue());
  }
  </code></pre>
  
  <p>Class XmlUtils-</p>
  
  <pre><code>import org.jdom.Document;
  import org.jdom.Element;
  import org.jdom.JDOMException;
  import org.jdom.input.SAXBuilder;
  import org.jdom.output.Format;
  import org.jdom.output.XMLOutputter;
  import org.xml.sax.InputSource;
  import org.apache.log4j.Logger;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.StringReader;
  import java.io.FileWriter;
  
  public class XmlUtils
  {
  private static final Logger logger = Logger.getLogger(XmlUtils.class);
  public static String getFormatedXMLString(String doc)  throws JDOMException, IOException
  {
      return (  makeDomToFormatedString( createDocument(doc)  ) ) ;
  }
  
  public static String makeDomToFormatedString(Document doc)
  {
      return makeDomToFormatedString(doc.getRootElement());
  }
  
  public static String makeDomToFormatedString(Element elem)
  {
      XMLOutputter output = new XMLOutputter();
  
      Format format = Format.getPrettyFormat();
      format.setExpandEmptyElements( true );
      format.setTextMode( Format.TextMode.TRIM_FULL_WHITE );
  
      output.setFormat( format );
      return output.outputString(elem);
  }
  
  public static Document createDocument(String xml) throws JDOMException, IOException
  {
      InputSource in = new InputSource(new StringReader(xml));
      SAXBuilder saxB = new SAXBuilder();
      return ((saxB.build(in)));
  }
  
  public static Element createElement(File xmlFile) throws JDOMException, IOException
  {
      SAXBuilder saxB = new SAXBuilder();
      Document document = saxB.build(xmlFile);
      return document.getRootElement();
  }
  
  
  public static void writeXmlFile(Document doc,String path){
  
      try {
          XMLOutputter xmlOutputer = new XMLOutputter();
  
          xmlOutputer.setFormat( Format.getPrettyFormat() );
          xmlOutputer.output( doc , new FileWriter( path ) );
  
      } catch (IOException e) {
         logger.error("cant write xml file",e);
      }
  }
  }
  </code></pre>