Hello, i am tryin to develop a little program to read xml from a file but the issue i am having is that if a specific tag doesnt exist the program falls over. What i need is some kind of if statement which will allow the program to continue, i just dont know how to go about it.
Java Code:
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException; 
import java.io.File;
import org.w3c.dom.Document;
import org.w3c.dom.*;



public class xmlReader{

    public static void main (String argv []){
    try {

            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            Document doc = docBuilder.parse (new File("meta.xml"));

            // normalize text representation
            doc.getDocumentElement ().normalize ();
            System.out.println ("Root element of the doc is " + 
                 doc.getDocumentElement().getNodeName());


            NodeList listOfPersons = doc.getElementsByTagName("office:meta");
            int totalPersons = listOfPersons.getLength();

            for(int s=0; s<listOfPersons.getLength() ; s++){


                Node nameFilterNode = listOfPersons.item(s);
                if(nameFilterNode.getNodeType() == Node.ELEMENT_NODE){


                    Element nameFilterElement = (Element)nameFilterNode;

                    //-------
                    NodeList initialCreatorList = nameFilterElement.getElementsByTagName("meta:initial-creator");
                    Element initialCreatorElement = (Element)initialCreatorList.item(0);

                    NodeList textInitialCreatorList = initialCreatorElement.getChildNodes();
                    System.out.println("Initial Creator : " + 
                           ((Node)textInitialCreatorList.item(0)).getNodeValue().trim());

                    //-------
                    NodeList creatorList = nameFilterElement.getElementsByTagName("dc:creator");
                    Element creatorElement = (Element)creatorList.item(0);

                    NodeList textCreatorList = creatorElement.getChildNodes();
                    System.out.println("Last Saved By : " + 
                           ((Node)textCreatorList.item(0)).getNodeValue().trim());

                    //----
                    NodeList printedByList = nameFilterElement.getElementsByTagName("meta:printed-by");
                    Element printedByElement = (Element)printedByList.item(0);

                    NodeList textPrintedByList = printedByElement.getChildNodes();
                    System.out.println("Last Printed By : " + 
                           ((Node)textPrintedByList.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


}
here is the xml file aswell, any help or atleast a point in the right direction would be greatly appreciated
XML Code:
 
 <?xml version="1.0" encoding="UTF-8" ?> 
- <office:document-meta>
 <office:meta>
  <meta:generator>OpenOffice.org/2.4$Linux OpenOffice.org_project/680m17$Build-9310</meta:generator> 
  <meta:initial-creator>Stacy</meta:initial-creator> 
  <meta:creation-date>2006-12-23T18:53:23</meta:creation-date> 
  <dc:creator>CEIS S2</dc:creator> 
  <dc:date>2009-01-06T14:20:34</dc:date> 
  <dc:language>en-US</dc:language> 
  <meta:editing-cycles>5</meta:editing-cycles> 
  <meta:editing-duration>PT1M13S</meta:editing-duration> 
  <meta:user-defined meta:name="Info 1" /> 
  <meta:user-defined meta:name="Info 2" /> 
  <meta:user-defined meta:name="Info 3" /> 
  <meta:user-defined meta:name="Info 4" /> 
  <meta:document-statistic meta:table-count="0" meta:image-count="0" meta:object-count="0" meta:page-count="128" meta:paragraph-count="6041" meta:word-count="63715" meta:character-count="405653" /> 
  </office:meta>
  </office:document-meta>