Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.DOMParser


    /** Main program. */
    public static void main(String argv[]) {

        // create parser and set features/properties
        DOMParser parser = new DOMParser();
        /***
        try { parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); }
        catch (Exception e) { System.err.println("warning: unable to set feature."); }
        /***/
        try { parser.setFeature("http://apache.org/xml/features/domx/grammar-access", true); }
        catch (Exception e) { System.err.println("warning: unable to set feature."); }

        // create grammar writer
        XGrammarWriter writer = new XGrammarWriter();

        // run through command line args
        if (argv.length == 0) {
            printUsage();
        }
        else {
            for (int i = 0; i < argv.length; i++) {
                String arg = argv[i];
                if (arg.startsWith("-")) {
                    if (arg.equals("-d") || arg.equals("--dtd")) {
                        writer.setOutputFormat(OutputFormat.DTD);
                        continue;
                    }
                    if (arg.equals("-x") || arg.equals("--schema")) {
                        writer.setOutputFormat(OutputFormat.XML_SCHEMA);
                        continue;
                    }
                    if (arg.equals("-v") || arg.equals("--verbose")) {
                        writer.setVerbose(true);
                        continue;
                    }
                    if (arg.equals("-q") || arg.equals("--quiet")) {
                        writer.setVerbose(false);
                        continue;
                    }
                    if (arg.equals("-h") || arg.equals("--help")) {
                        printUsage();
                        break;
                    }
                    if (arg.equals("--")) {
                        if (i < argv.length - 1) {
                            System.err.println("error: Missing argument to -- option.");
                            break;
                        }
                        arg = argv[++i];
                        // let fall through
                    }
                    else {
                        System.err.println("error: Unknown option ("+arg+").");
                    }
                }

                // parse file and print grammar
                try {
                    parser.parse(arg);
                    Document document = parser.getDocument();
                    writer.printGrammar(arg, document.getDoctype());
                }
                catch (Exception e) {
                    System.err.println("error: Error parsing document ("+arg+").");
                    e.printStackTrace(System.err);
View Full Code Here


   * Create a List of strategy implentations from the XML.
   */
  protected void createStrategies() {
    strategyImpls = new ArrayList<FileNamingStrategy>();
    try {
      DOMParser parser = new DOMParser();
      InputSource source = new InputSource(new StringReader(getStrategies()));
      parser.parse(source);
      Document doc = parser.getDocument();
      NodeList strategyNodes = doc.getElementsByTagName(ELEMENT_STRATEGY);
      for (int i = 0; i < strategyNodes.getLength(); i++) {
        FileNamingStrategy strategy = createStrategy(strategyNodes.item(i));
        strategyImpls.add(strategy);
      }
View Full Code Here

          } catch (Exception exsx)
          {}
          return;
       }
       //  Create a Xerces DOM Parser
       DOMParser parser = new DOMParser();
       //  Parse the Document
       //  and traverse the DOM
       try
       {
         
          parser.setEntityResolver( new org.xml.sax.EntityResolver()
          {
             /* Code by Teodor Danciu */
             public org.xml.sax.InputSource resolveEntity(
             String publicId,
             String systemId
             ) throws SAXException//, java.io.IOException
             {
                org.xml.sax.InputSource inputSource = null;
               
                if (systemId != null)
                {
                   String dtd = null;
                  
                   if (
                   systemId.equals("http://ireport.sourceforge.net/dtds/iReportFilesList.dtd")
                   )
                   {
                      dtd = "it/businesslogic/ireport/dtds/iReportFilesList.dtd";
                   }
                   else
                   {
                      return new org.xml.sax.InputSource(systemId);
                   }
                  
                   ClassLoader classLoader = this.getClass().getClassLoader();
                  
                   java.net.URL url = null;
                  
                  
                   if (classLoader != null)
                   {
                      url = classLoader.getResource(dtd);
                   }
                   if (url == null)
                   {
                      classLoader = this.getClass().getClassLoader();
                   }
                  
                   java.io.InputStream is = classLoader.getResourceAsStream(dtd);
                   if (is != null)
                   {
                      java.io.InputStreamReader isr = new java.io.InputStreamReader(is);
                      inputSource = new org.xml.sax.InputSource(isr);
                   }
                  
                }
               
                return inputSource;
             }
          });
          /* End Code by Teodor Danciu */
          parser.parse( new java.io.File(xmlFile).toURI().toString() );
          Document document = parser.getDocument();
         
          // Traverse the tree until we don't find a iReportFilesList element...
          Node fileList = goToNodeElement("iReportFilesList",document.getDocumentElement());
          if (fileList == null) return;
          NodeList list = fileList.getChildNodes();
View Full Code Here

            System.out.println("\nLevelZeroTest.testString() - started\n");

            // read in the text file so we have something to compare with
            BufferedReader in = new BufferedReader(new FileReader(xmlFileName));
            InputSource source = new InputSource(in);
            DOMParser parser = new DOMParser();
            parser.parse(source);
            String xmlString = toString(parser.getDocument()).trim();
            XMLResource res = insertStringDocument(id, super.toString(document));

            String result = retrieveTextDocument(id).trim();

            super.assertNotNull("LevelZeroTest.testString() - result", result);
View Full Code Here

        }
    } 
    Document parseDocument() throws Exception {
        BufferedReader in = new BufferedReader(new FileReader(fileName));
        InputSource source = new InputSource(in);
        DOMParser parser = new DOMParser();
        parser.parse(source);    
        return parser.getDocument();
    }
View Full Code Here

        }
    } 
    Document parseDocument() throws Exception {
        BufferedReader in = new BufferedReader(new FileReader(fileName));
        InputSource source = new InputSource(in);
        DOMParser parser = new DOMParser();
        parser.parse(source);    
        return parser.getDocument();
    }
View Full Code Here

                "</ns1:buff>" +
                "    </ns1:stringToDataHandler>" +
                " </soapenv:Body>" +
                "</soapenv:Envelope>";           

      DOMParser parser = new DOMParser();

      parser.parse(new InputSource(new StringReader(inputDoc)));
      Element element = parser.getDocument().getDocumentElement();
      NodeList l = element.getChildNodes();
      Element e1 = (Element)l.item(1);
      l = e1.getChildNodes();
      element = (Element)l.item(1);
      Node n = e1.getFirstChild();
View Full Code Here

                  "   <ns1:file href=\"cid:413B07CE410E48EB9D89DC0A4DDD715D\"/>" +
                  "  </ns1:bounceImage4>" +
                  " </soapenv:Body>" +
                  "</soapenv:Envelope>";

      DOMParser parser = new DOMParser();

      parser.parse(new InputSource(new StringReader(inputDoc)));
      Element element = parser.getDocument().getDocumentElement();
      NodeList l = element.getChildNodes();
      Element e1 = (Element)l.item(1);
      l = e1.getChildNodes();
      element = (Element)l.item(1);
      Node n = e1.getFirstChild();
View Full Code Here

          + "<address>607 Trinity</address>"
          + "<city>Austin</city>"
          + "<state>TX</state>"
          + "</ShortZipCode>";

      DOMParser parser = new DOMParser();
      String xmlString = "<?xml version=\"1.0\"?>\n" + inputDocument;
      parser.parse(new InputSource(new StringReader(xmlString)));
      Element element = parser.getDocument().getDocumentElement();
      //printElement(element);

      inMsg.setObjectPart("parameters", element);

      boolean ok =
View Full Code Here

      WSIFMessage faultMsg = operation.createFaultMessage();
     
      String inputDocument =
        "<GetRatesXML xmlns=\"http/www.pointwsp.net/ws/finance\"/>";

      DOMParser parser = new DOMParser();
      String xmlString = "<?xml version=\"1.0\"?>\n" + inputDocument;
      parser.parse(new InputSource(new StringReader(xmlString)));
      Element element = parser.getDocument().getDocumentElement();
      //printElement(element);

      inMsg.setObjectPart("parameters", element);
     
      boolean ok =
View Full Code Here

TOP

Related Classes of org.apache.xerces.parsers.DOMParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.