title: Read xml file which has 2 root node?
body: <p>input file
  xml </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;response&gt;
      &lt;message&gt;&lt;/message&gt;
      &lt;messagecode&gt;&lt;/messagecode&gt;
      &lt;messagedescription&gt;&lt;/messagedescription&gt;
  &lt;/response&gt;
  &lt;response&gt;
      &lt;message&gt;&lt;/message&gt;
      &lt;messagecode&gt;&lt;/messagecode&gt;
      &lt;messagedescription&gt;&lt;/messagedescription&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>two response --
  response id root node..
  Java code</p>
  
  <pre><code>public void readXML(String output) {
      try {
  
          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
          Document doc = dBuilder.parse(output);
  
          doc.getDocumentElement().normalize();
          NodeList nodes = doc.getElementsByTagName("response");
  
          for (int i = 0; i &lt; nodes.getLength(); i++) {
  
              Node nNode = nodes.item(i);
              if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                  Element element = (Element) nNode;
                   NodeList msg = element.getElementsByTagName("message");
                   Element line = (Element) msg.item(i);
                   System.out.println("Message: " + getCharacterDataFromElement(line));
  
                   NodeList msgcode = element.getElementsByTagName("messagecode");
                   line = (Element) msgcode.item(i);
                   System.out.println("Message Code: " + getCharacterDataFromElement(line));
  
                   NodeList msgdes = element.getElementsByTagName("messagedescription");
                   line = (Element) msgdes.item(i);
                   System.out.println("Message Description: " + getCharacterDataFromElement(line));
  
                   NodeList medialink = element.getElementsByTagName("medialink");
                   line = (Element) medialink.item(i);
                   System.out.println("Media link: " + getCharacterDataFromElement(line));
  
                   NodeList mediastatus = element.getElementsByTagName("mediastatus");
                   line = (Element) mediastatus.item(i);
                   System.out.println("Media Status: " + getCharacterDataFromElement(line));
  
              }
  
          }
      } catch (ParserConfigurationException e) {
          e.printStackTrace();
      } catch (SAXException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  
  public static String getCharacterDataFromElement(Element e) {
      Node child = e.getFirstChild();
      if (child instanceof CharacterData) {
          CharacterData cd = (CharacterData) child;
          return cd.getData();
      }
      return "";
  }
  </code></pre>
  
  <p>i try this code but error will display how can i reslove this....
  SAX Exception will give error in not well formed xml file.
  how can i read two root node values in same java file..</p>