title: How get parent element attribute and child value from XML in java?
body: <p>I have a XML file, for example:</p>
  
  <pre><code>&lt;parent value="first"&gt;
    &lt;child&gt;Bill&lt;/child&gt;
  &lt;/parent&gt;
  </code></pre>
  
  <p>I want to get at output: value=first,child=Bill
  That means I need attribute from parrent element and value from child element.</p>
  
  <p>I tried to do something like this:</p>
  
  <pre><code>List&lt;Str&gt; obj = new ArrayList&lt;Str&gt;();
  NodeList nList  = doc.getElementsByTagName("parent");
  for (int i = 0; i &lt; nList.getLength(); ++i) {
      Element attrElement = (Element) nList.item(i);
      NamedNodeMap map = attrElement.getAttributes();
         for (int j = 0; j &lt; map.getLength(); j++) {
              Node attribute = map.item(j);
              Node eNode = nList.item(j);
              Element name = (Element) eNode;
              obj.add(new Str(attribute.getNodeValue(), name.getElementsByTagName("child").item(0).getTextContent()));
         }
      }
  </code></pre>
  
  <p>In result i have Str with "null" values.</p>