title: Java:How to get Attribute name from xml in Java?(JDOM)
body: <p>Java: 
  How to get Attribute Name of the node Using <code>JAVA-JDOM</code>? 
  For Example,</p>
  
  <pre><code>&lt;xml&gt;
      &lt;Test id="001"&gt;&lt;/Test&gt;
  &lt;/xml&gt;
  </code></pre>
  
  <p>The Output Should be:</p>
  
  <pre><code>id
  </code></pre>
  
  <p>My Java Program: In ______ Needs to get Attribute Name of node which as it is in Source file. This Program Just adds "_Test" to all nodes in the xml File and replace the same file.</p>
  
  <pre><code>try
      {
      XMLOutputter  xmlOut = new XMLOutputter();
      SAXBuilder builder = new SAXBuilder();
      File xmlFile = new File("D://Test//sample.xml");
      Document document = (Document) builder.build(xmlFile);
      Element rootNode = document.getRootElement();
      String Original_data=xmlOut.outputElementContentString(rootNode);
      String Test_Data="",Output_Data;
      List&lt;?&gt; list = rootNode.getChildren();
      PrintStream out = new PrintStream(new FileOutputStream("D://Test/sample.xml"));
      Element node=null;
      for(int i=0;i&lt;list.size();i++)
        {
          node=(Element) list.get(i);
          Test_Data+="&lt;"+node.getName()+"_Test "+__________+"="+node.getAttributeValue(________)+"&gt;"; //In ______ Needs to get Only Name of Attribute.
  
          List&lt;?&gt; n_list=node.getChildren();
          Element node2=null;
          for(int j=0;j&lt;n_list.size();j++)
          {
              node2=(Element) n_list.get(j);
  
                String Str = new String(xmlOut.outputString(node2));
                Test_Data+=Str.replace(node2.getName(),node2.getName()+"_Test");
          }
          Test_Data+="&lt;/"+node.getName()+"_Test&gt;";
        }
      out.println("&lt;"+rootNode.getName()+"&gt;"+Original_data+Test_Data+"&lt;/"+rootNode.getName()+"&gt;");
      }
  </code></pre>
  
  <p>Sample.xml</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;catalog&gt;
   &lt;book id="bk101_Test"&gt;
    &lt;author&gt;_Worked&lt;/author&gt;
    &lt;title&gt;XML Developer's Guide&lt;/title&gt;
    &lt;genre&gt;Computer&lt;/genre&gt;
    &lt;price&gt;44.95&lt;/price&gt;
    &lt;publish_date&gt;2000-10-01&lt;/publish_date&gt;
    &lt;description&gt;An in-depth look at creating applications 
    with XML.&lt;/description&gt;    
  &lt;/book&gt;
    &lt;book id="bk112_Test"&gt;
    &lt;author&gt;Galos, Mike&lt;/author&gt;
    &lt;title&gt;Visual Studio 7: A Comprehensive Guide&lt;/title&gt;
    &lt;genre&gt;Computer&lt;/genre&gt;
    &lt;price&gt;49.95&lt;/price&gt;
    &lt;publish_date&gt;2001-04-16&lt;/publish_date&gt;
    &lt;description&gt;Microsoft Visual Studio 7 is explored in depth,
    looking at how Visual Basic, Visual C++, C#, and ASP+ are 
    integrated into a comprehensive development 
    environment.&lt;/description&gt;    
  &lt;/book&gt;
  &lt;/catalog&gt;
  </code></pre>