title: Parser- how to read the file?
body: <p>I'm a java-beginner and also programming-beginner and I want to implement a DOM-Parser. My Problem: I don't know, how to read the file into the Parser. I tried to use the IBM-Parser with DOM.</p>
  
  <pre><code>package domparser;
  import org.w3c.dom.*;
  import com.ibm.xml.parsers.*;
  
  public class domparser
  {
  public static void main(String[] args)
  {
      domparser MyParser = new domparser();
      MyParser.parse(args[0]);
  }
  
  private void parse(String file)
  {
      NonValidatingDOMParser parser = new NonValidatingDOMParser();
      try
      {
         parser.parse(file);
         writeDoc(parser.getDocument().getDocumentElement());
      }
      catch (Exception e)
      {
          System.err.println("Fehler: " + e);
      }
  }
  
  private void writeDoc(Node node)
  {
      short type = node.getNodeType();
      switch (type)
      {
          case Node.ELEMENT_NODE:
          {
              String name = "&lt;" + node.getNodeName();
              NamedNodeMap attrs = node.getAttributes();
              if (attrs != null)
              {
                  int length = attrs.getLength();
                  for (int i = 0; i &lt; length; i++)
                  {
                      Node attr =  attrs.item(i);
                      name += " " + attr.getNodeName();
                      name += "=\"" + attr.getNodeValue() + "\"";
                  }
              }
              name += "&gt;";
              System.out.println(name);
  
              NodeList children = node.getChildNodes();
              if (children != null)
              {
                  int length = children.getLength();
                  for (int i = 0; i &lt; length; i++)
                      writeDoc(children.item(i));
              }
              break;
          }
          case Node.TEXT_NODE:
          {
              System.out.println(node.getNodeValue());
              break;
          }
      }
  }
  }
  </code></pre>
  
  <p>Thank you!</p>