Package org.apache.xerces.parsers

Examples of org.apache.xerces.parsers.DOMParser


        else
            log.debug("URL to org.jboss.dashboard.ui.panel.help.help.xsd is [" + schemaUrl.toString() + "].");
        String schema = schemaUrl.toString();

        // Create a DOMParser
        DOMParser parser = new DOMParser();

        // Set the validation feature
        parser.setFeature("http://xml.org/sax/features/validation", true);

        // Set the schema validation feature
        parser.setFeature("http://apache.org/xml/features/validation/schema", true);

        // Set schema full grammar checking
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

        // Disable whitespaces
        parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace", false);

        // Set schema location
        parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schema);

        // Set the error handler
        parser.setErrorHandler(new ErrorHandler() {
            public void error(SAXParseException exception) throws SAXParseException {
                throw exception;
            }

            public void fatalError(SAXParseException exception) throws SAXParseException {
                throw exception;
            }

            public void warning(SAXParseException exception) {
            }
        });

        // Parse the XML document
        parser.parse(new InputSource(is));

        return parser.getDocument();
    }
View Full Code Here


        if (serializedData == null || serializedData.trim().length() == 0) {
            log.info("No data to deserialize.");
            return false;
        }

        DOMParser parser = new DOMParser();
        parser.parse(new InputSource(new StringReader(serializedData)));
        Document doc = parser.getDocument();
        NodeList nodes = doc.getElementsByTagName("dashboard_filter");
        if (nodes.getLength() > 1) {
            log.error("Each dashboard filter component just can parse one <dashboard_filter>");
            return false;
        }
View Full Code Here

        if (schemaUrl == null) log.error("Could not find [org.jboss.dashboard.workspace.export.workspace.xsd]. Used [" + getClass().getClassLoader() + "] class loader in the search.");
        else log.debug("URL to org.jboss.dashboard.workspace.export.workspace.xsd is [" + schemaUrl.toString() + "].");
        String schema = schemaUrl.toString();

        //Create a DOMParser
        DOMParser parser = new DOMParser();

        //Set the validation feature
        parser.setFeature("http://xml.org/sax/features/validation", true);

        //Set the schema validation feature
        parser.setFeature("http://apache.org/xml/features/validation/schema", true);

        //Set schema full grammar checking
        parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);

        //Disable whitespaces
        parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace", false);

        //Set schema location
        parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schema);

        //Set the error handler
        parser.setErrorHandler(new ErrorHandler() {
            public void error(SAXParseException exception) throws SAXParseException {
                throw exception;
            }

            public void fatalError(SAXParseException exception) throws SAXParseException {
                throw exception;
            }

            public void warning(SAXParseException exception) {
                /*getWarnings().add(exception.getMessage());
                getWarningArguments().add(new Object[]{exception});*/
            }
        });

        // Put it in a byte array before because the parser closes the stream.
        ByteArrayOutputStream bos = new ByteArrayOutputStream(is.available());
        int byteRead;
        while ((byteRead = is.read()) != -1) {
            bos.write(byteRead);
        }

        //Parse the XML document
        parser.parse(new InputSource(new ByteArrayInputStream(bos.toByteArray())));

        Document doc = parser.getDocument();
        init(doc);
    }
View Full Code Here

    }

    public void deserializeDataProperties(DataSet dataSet) throws Exception {
        if (StringUtils.isBlank(dataPropertiesXML)) return;

        DOMParser parser = new DOMParser();
        parser.parse(new InputSource(new StringReader(dataPropertiesXML)));
        Document doc = parser.getDocument();
        NodeList nodes = doc.getElementsByTagName("dataproperty");
        dataSet.parseXMLProperties(nodes);
    }
View Full Code Here

            fCurrentSchemaInfo = (SchemaInfo)(fRedefineLocations.get((Object)location));
            fCurrentSchemaInfo.restore();
            return;
        }

        DOMParser parser = new IgnoreWhitespaceParser();
        parser.setEntityResolver( (fEntityResolver != null)? (fEntityResolver):(new Resolver()) );
        parser.setErrorHandlernew ErrorHandler() );

        try {
            parser.setFeature("http://xml.org/sax/features/validation", false);
            parser.setFeature("http://xml.org/sax/features/namespaces", true);
            parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
            parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        }catchorg.xml.sax.SAXNotRecognizedException e ) {
            e.printStackTrace();
        }catch( org.xml.sax.SAXNotSupportedException e ) {
            e.printStackTrace();
        }

        try {
            parser.parse( source );
        }catch( IOException e ) {
            e.printStackTrace();
        }catch( SAXException e ) {
            //e.printStackTrace();
        }

        Document     document   = parser.getDocument(); //Our Grammar to be redefined
        Element root = null;
        if (document != null) {
            root = document.getDocumentElement();
        }
View Full Code Here

        if(source.getSystemId().equals(fCurrentSchemaURL)) {
            // REVISIT:  localize
            return null;
        }

         DOMParser parser = new IgnoreWhitespaceParser();
         parser.setEntityResolver( (fEntityResolver != null)? (fEntityResolver):(new Resolver()) );
         parser.setErrorHandler( new ErrorHandler  ()
            {
                public void fatalError(SAXParseException ex) throws SAXException {
                    StringBuffer str = new StringBuffer();
                    String systemId_ = ex.getSystemId();
                    if (systemId_ != null) {
                        int index = systemId_.lastIndexOf('/');
                        if (index != -1)
                            systemId_ = systemId_.substring(index + 1);
                        str.append(systemId_);
                    }
                    str.append(':').append(ex.getLineNumber()).append(':').append(ex.getColumnNumber());
                    String message = ex.getMessage();
                    if(message.toLowerCase().trim().endsWith("not found.")) {
                        System.err.println("[Warning] "+
                               str.toString()+": "+ message);
                    } else { // do standard thing
                        System.err.println("[Fatal Error] "+
                               str.toString()+":"+message);
                        throw ex;
                    }
                }
            });

         try {
             parser.setFeature("http://xml.org/sax/features/validation", false);
             parser.setFeature("http://xml.org/sax/features/namespaces", true);
             parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
             parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
         }catchorg.xml.sax.SAXNotRecognizedException e ) {
             e.printStackTrace();
         }catch( org.xml.sax.SAXNotSupportedException e ) {
             e.printStackTrace();
         }

         try {
             parser.parse( source );
         }catch( IOException e ) {
             e.printStackTrace();
         }catch( SAXException e ) {
             e.printStackTrace();
         }

         Document     document   = parser.getDocument(); //Our Grammar
         Element root = null;
         if (document != null) {
             root = document.getDocumentElement();
         }
         if(root != null) {
View Full Code Here

        if (fIncludeLocations.contains((Object)location)) {
            return;
        }
        fIncludeLocations.addElement((Object)location);

        DOMParser parser = new IgnoreWhitespaceParser();
        parser.setEntityResolver( (fEntityResolver != null)? (fEntityResolver):(new Resolver()) );
        parser.setErrorHandlernew ErrorHandler()
            {
                public void fatalError(SAXParseException ex) throws SAXException {
                    StringBuffer str = new StringBuffer();
                    String systemId_ = ex.getSystemId();
                    if (systemId_ != null) {
                        int index = systemId_.lastIndexOf('/');
                        if (index != -1)
                            systemId_ = systemId_.substring(index + 1);
                        str.append(systemId_);
                    }
                    str.append(':').append(ex.getLineNumber()).append(':').append(ex.getColumnNumber());
                    String message = ex.getMessage();
                    if(message.toLowerCase().trim().endsWith("not found.")) {
                        System.err.println("[Warning] "+
                               str.toString()+": "+ message);
                    } else { // do standard thing
                        System.err.println("[Fatal Error] "+
                               str.toString()+":"+message);
                        throw ex;
                    }
                }
            });

        try {
            parser.setFeature("http://xml.org/sax/features/validation", false);
            parser.setFeature("http://xml.org/sax/features/namespaces", true);
            parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
            parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
        }catchorg.xml.sax.SAXNotRecognizedException e ) {
            e.printStackTrace();
        }catch( org.xml.sax.SAXNotSupportedException e ) {
            e.printStackTrace();
        }

        try {
            parser.parse( source );
        }catch( IOException e ) {
            e.printStackTrace();
        }catch( SAXException e ) {
            //e.printStackTrace();
        }

        Document     document   = parser.getDocument(); //Our Grammar
        Element root = null;
        if (document != null) {
            root = document.getDocumentElement();
        }
View Full Code Here

    ULCONTENT[3]="operate at minimal cost" ;
  }

  @Test
  public void testSkipChildren() {
    DOMParser parser= new DOMParser();
   
    try {
      parser.setFeature("http://xml.org/sax/features/validation", false);
      parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
      parser.parse(new InputSource(new ByteArrayInputStream(WEBPAGE.getBytes())));
    } catch (Exception e) {
      e.printStackTrace();
    }
    
    StringBuffer sb = new StringBuffer();
    NodeWalker walker = new NodeWalker(parser.getDocument());
    while (walker.hasNext()) {
      Node currentNode = walker.nextNode();
      short nodeType = currentNode.getNodeType();
      if (nodeType == Node.TEXT_NODE) {
        String text = currentNode.getNodeValue();
        text = text.replaceAll("\\s+", " ");
        sb.append(text);
      }
    }
    Assert.assertTrue("UL Content can NOT be found in the node", findSomeUlContent(sb.toString()));
    
   StringBuffer sbSkip = new StringBuffer();
   NodeWalker walkerSkip = new NodeWalker(parser.getDocument());
   while (walkerSkip.hasNext()) {
     Node currentNode = walkerSkip.nextNode();
     String nodeName = currentNode.getNodeName();
     short nodeType = currentNode.getNodeType();
     if ("ul".equalsIgnoreCase(nodeName)) {
View Full Code Here

    // this creates the new Annotation element as the first child
    // of the Node
    private synchronized void writeToDOM(Node target, short type){
        Document futureOwner = (type == XSAnnotation.W3C_DOM_ELEMENT)?target.getOwnerDocument():(Document)target;
        DOMParser parser = fGrammar.getDOMParser();
        StringReader aReader = new StringReader(fData);
        InputSource aSource = new InputSource(aReader);
        try {
            parser.parse(aSource);
        } catch (SAXException e) {
            // this should never happen!
            // REVISIT:  what to do with this?; should really not
            // eat it...
        } catch (IOException i) {
            // ditto with above
        }
        Document aDocument = parser.getDocument();
        Element annotation = aDocument.getDocumentElement();
        Node newElem = futureOwner.importNode(annotation, true);
        target.insertBefore(newElem, target.getFirstChild());
    }
View Full Code Here

        // note that this should never produce errors or require
        // entity resolution, so just a barebones configuration with
        // a couple of feature  set will do fine
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE, true);
        config.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, false);
        fDOMParser = new DOMParser(config);
        return fDOMParser;
    }
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.