Package javax.xml.parsers

Examples of javax.xml.parsers.DocumentBuilderFactory


     * web.xml application deployment descriptors.
     */
    private Document parseStreamToXML(InputStream in) {
        try {
            // Use JAXP to create a document builder
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setExpandEntityReferences(false);
            factory.setValidating(false);
            factory.setNamespaceAware(false);
            factory.setIgnoringComments(true);
            factory.setCoalescing(true);
            factory.setIgnoringElementContentWhitespace(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(in);
        } catch (Throwable errParser) {
            throw new WinstoneException(REALM_RESOURCES
                    .getString("FileRealm.XMLParseError"), errParser);
        }
View Full Code Here


        InputSource is = getSchemaInputSource(baseURI, location);

        Document document = null;
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder parser = factory.newDocumentBuilder();
            document = parser.parse(is);
        } catch (ParserConfigurationException ex) {
            throw new ConfigurationException(new Message("PARSER_CONFIGURATION_ERROR_EXC",
                                                         LOG, location), ex);
        } catch (SAXException ex) {
            throw new ConfigurationException(new Message("PARSE_ERROR_EXC", LOG), ex);
        } catch (IOException ex) {
            throw new ConfigurationException(new Message("FILE_OPEN_ERROR_EXC", LOG, location), ex);
        }

        deserialize(document);

        Source src = new DOMSource(document);
        src.setSystemId(is.getSystemId());

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        final LSResourceResolver oldResolver = factory.getResourceResolver();
    
        LSResourceResolver resolver = new LSResourceResolver() {

            public LSInput resolveResource(String type, String nsURI,
                                           String publicId, String systemId, String baseURI) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("resolving resource type: " + type + "\n"
                            + "                   namespaceURI:" + nsURI + "\n"
                            + "                   publicId:" + publicId + "\n"
                            + "                   systemId:" + systemId + "\n"
                            + "                   baseURI:" + baseURI);
                }
               
                if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(type)) {
                    LSInput lsi = new SchemaInput(type, nsURI, publicId, systemId, baseURI);
                    String resourceName = systemId;
                   
                    InputSource src = getSchemaInputSource(baseURI, resourceName);
                    lsi.setByteStream(src.getByteStream());
                    lsi.setSystemId(src.getSystemId());
                    return lsi;
                }
                return oldResolver == null ? null
                    : oldResolver.resolveResource(type, nsURI, publicId, systemId, baseURI);
            }
        };
       
        factory.setResourceResolver(resolver);       
        try {
            schema = factory.newSchema(src);
        } catch (SAXException ex) {
            throw new ConfigurationException(new Message("SCHEMA_CREATION_ERROR_EXC", LOG, location), ex);
        }
        document = null;
       
View Full Code Here

    private void parseXML(InputSource is) throws IOException {

        // parse
        Document document = null;
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder parser = factory.newDocumentBuilder();
            document = parser.parse(is);
        } catch (ParserConfigurationException ex) {
            throw new ConfigurationException(new Message("PARSER_CONFIGURATION_ERROR_EXC", LOG), ex);
        } catch (SAXException ex) {
            throw new ConfigurationException(new Message("PARSE_ERROR_EXC", LOG), ex);
View Full Code Here

     * @throws SAXException
     */
    private Document urlToDocument(String url)
        throws Exception
    {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setEntityResolver(new XslTransformerEntityResolver(url));
        return builder.parse(new InputSource(url));
    }
View Full Code Here

        assertEquals(qn, ConfigurationMetadataUtils.elementAttributeToQName(doc, elem, "name"));
    }
   
    private Document getDocument(String str) throws Exception {
        if (null == document) {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            DocumentBuilder parser = factory.newDocumentBuilder();
            document = parser.parse(new InputSource(new ByteArrayInputStream(str.getBytes())));
        }
        return document;
    }
View Full Code Here

  }

  public void testXMPSchemaBibtexElement()
    throws ParserConfigurationException {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory
      .newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    Element e = builder.newDocument().createElement("rdf:Description");

    XMPSchemaBibtex bibtex = new XMPSchemaBibtex(e, "bibtex");

    assertEquals(e, bibtex.getElement());
View Full Code Here

            long XX_prng_end = System.currentTimeMillis();

            /* read library configuration file */
            long XX_parsing_start = System.currentTimeMillis();
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

            dbf.setNamespaceAware(true);
            dbf.setValidating(false);

            DocumentBuilder db = dbf.newDocumentBuilder();
     
      // We don't allow users to override the Apache XML Security
      // configuration in the JRE. Users should use the standard security
      // provider mechanism instead if implementing their own
      // transform or canonicalization algorithms.
View Full Code Here

                  java.io.IOException, org.xml.sax.SAXException,
                  CanonicalizationException {

      ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
      InputSource in = new InputSource(bais);
      DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();

      dfactory.setNamespaceAware(true);

      // needs to validate for ID attribute nomalization
      dfactory.setValidating(true);

      DocumentBuilder db = dfactory.newDocumentBuilder();

      /*
       * for some of the test vectors from the specification,
       * there has to be a validatin parser for ID attributes, default
       * attribute values, NMTOKENS, etc.
View Full Code Here

                  java.io.IOException, org.xml.sax.SAXException,
                  CanonicalizationException {

      java.io.ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
      InputSource in = new InputSource(bais);
      DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();

      // needs to validate for ID attribute nomalization
      dfactory.setNamespaceAware(true);

      DocumentBuilder db = dfactory.newDocumentBuilder();

      /*
       * for some of the test vectors from the specification,
       * there has to be a validatin parser for ID attributes, default
       * attribute values, NMTOKENS, etc.
View Full Code Here

        
         try
         {
            is = new ByteArrayInputStream(config);     
        
            DocumentBuilderFactory docBuilderFactory = null;
           
            docBuilderFactory = DocumentBuilderFactory.newInstance();
           
            docBuilderFactory.setValidating(false);
           
            InputSource source = new InputSource(is);
           
            URL url = AspectXmlLoader.class.getResource("/jboss-aop_1_0.dtd");
           
            source.setSystemId(url.toString());
           
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
           
            docBuilder.setEntityResolver(new Resolver());
           
            Document doc = docBuilder.parse(source);
           
View Full Code Here

TOP

Related Classes of javax.xml.parsers.DocumentBuilderFactory

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.