title: How to create POJO class for xml parse in java?
body: <p>I got exact output what I need, but I have to use POJO class for my program, I searched lot for issue, but I didnt get clear idea.Help me to solve this issue,thanks in advance, my coding for xml pharse in java given below.</p>
  
  <p>Coding for ReadAndPrintXMLFile::</p>
  
  <pre><code>import org.w3c.dom.*;
  
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.DocumentBuilder;
  import org.xml.sax.SAXException;
  import org.xml.sax.SAXParseException;
  
  import java.net.URL;
  import java.io.InputStream;
  
  public class ReadAndPrintXMLFile{
      public static void main (String argv []){
  
  
      try {
              DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
              DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
  
              URL url = new URL("http://xxxxxxxxxxxxxxxx");
              InputStream stream = url.openStream();
              Document doc = docBuilder.parse(stream);
  
              // normalize text representation
              doc.getDocumentElement ().normalize ();
              System.out.println ("Root element of the doc is " +
                   doc.getDocumentElement().getNodeName());
              NodeList listOfPersons = doc.getElementsByTagName("head");
              int totalPersons = listOfPersons.getLength();
              System.out.println("Total no of head : " + totalPersons);
              for(int s=0; s&lt;listOfPersons.getLength() ; s++){
                  Node firstPersonNode = listOfPersons.item(s);
                  if(firstPersonNode.getNodeType() == Node.ELEMENT_NODE){
                      Element firstPersonElement = (Element)firstPersonNode;
                      //-------
                      NodeList firstNameList = firstPersonElement.getElementsByTagName("heading");
                      Element firstNameElement = (Element)firstNameList.item(0);
                      NodeList textFNList = firstNameElement.getChildNodes();
                      System.out.println("Heading : " +
                             ((Node)textFNList.item(0)).getNodeValue().trim());
  
                  }//end of if clause
              }//end of for loop with s var
          }catch (SAXParseException err) {
          System.out.println ("** Parsing error" + ", line "
               + err.getLineNumber () + ", uri " + err.getSystemId ());
          System.out.println(" " + err.getMessage ());
          }catch (SAXException e) {
          Exception x = e.getException ();
          ((x == null) ? e : x).printStackTrace ();
          }catch (Throwable t) {
          t.printStackTrace ();
          }
          //System.exit (0);
      }//end of main
  }
  </code></pre>
  
  <p>For this xml parse program I  have to POJO class, .So For this I create a class like this</p>
  
  <pre><code>public class POJOurl {
  
      private String heading;
  
      public String getHeading() {
          return heading;
      }
  
      public void setHeading(String heading) {
          this.heading = heading;
      }
  
  
  }
  </code></pre>
  
  <p>Here I dont know how to use thse get and set method in my program, using these public String getHeading() and public void setHeading(String heading) I have to execute the program.. and I have to get the output what I am getting now.. only thing is I have to use POJO class for this program</p>
  
  <p>Output::</p>
  
  <pre><code>Root element of the doc is root1
  Total no of head : 4
  Heading : Appliance Repairs
  Heading : Air conditioning and refrigeration services
  Heading : Accountants
  Heading : Accident Management
  </code></pre>