title: How to get all attributes from each element separately?
body: <p>Here's some basic xml doc:</p>
  
  <pre><code>&lt;h1&gt;My Heading&lt;/h1&gt;
  
  &lt;p align = "center"&gt; My paragraph
  &lt;img src="smiley.gif" alt="Smiley face" height="42" width="42"&gt;&lt;/img&gt;
  &lt;img src="sad.gif" alt="Sad face" height="45" width="45"&gt;&lt;/img&gt;
  &lt;img src="funny.gif" alt="Funny face" height="48" width="48"&gt;&lt;/img&gt;
  &lt;/p&gt;
  &lt;p&gt;My para&lt;/p&gt;
  </code></pre>
  
  <p>What am i trying to do is find element, all his attributes and save attribute name + attribute value for each element. Here's my code so far:</p>
  
  <pre><code>private Map &lt;String, String&gt; tag = new HashMap &lt;String,String&gt; ();
  
  public Map &lt;String, String&gt; findElement () {
      try {
          FileReader fRead = new FileReader (sourcePage);
          BufferedReader bRead = new BufferedReader (fRead);
  
          DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance ();
          DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder ();
          Document doc = docBuilder.parse(new FileInputStream (new File (sourcePage)));
          XPathFactory xFactory = XPathFactory.newInstance ();
          XPath xPath = xFactory.newXPath ();
          NodeList nl = (NodeList) xPath.evaluate("//img/@*", doc, XPathConstants.NODESET); 
          for( int i=0; i&lt;nl.getLength (); i++) {
              Attr attr = (Attr) nl.item(i);
              String name = attr.getName();
              String value = attr.getValue();
              tag.put (name,value); 
          }
          bRead.close ();
          fRead.close ();
      }
      catch (Exception e) {
          e.printStackTrace();
          System.err.println ("An error has occured.");           
      }       
  </code></pre>
  
  <p>Problem appears when i am looking for img's attributes, because of identical attributes. HashMap is not suitable for this, for its overwriting of values with the same key. Maybe i'm using wrong expression to find all attributes. Is there any other way, how to get attributes names and values of nth img element?</p>