Package javax.xml.parsers

Examples of javax.xml.parsers.DocumentBuilderFactory


   */
  @Test
  @SuppressWarnings("nls")
  public void testW3CDocument() throws Exception {
    InputStream inS = getClass().getResourceAsStream("/data/interpreter/feed_opml.xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();

    InputSource source = new InputSource(inS);
    org.w3c.dom.Document doc = documentBuilder.parse(source);
    inS.close();

View Full Code Here


        boolean inEAR = container.getApplicationName() != null;

        // Create XML document...

        // Create builder with factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new IllegalStateException("Cannot build document builder", e);
        }

        // Create Document
View Full Code Here

     * @return an application object.
     */
    public static Document getDocument(final URL url, final boolean isValidating, final EntityResolver entityResolver)
            throws DocumentParserException {
        // build factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        // XML files use schemas.
        factory.setNamespaceAware(true);
        factory.setValidating(isValidating);

        // ignore white space can only be set if parser is validating
        if (isValidating) {
            factory.setIgnoringElementContentWhitespace(true);
            factory.setAttribute("http://apache.org/xml/features/validation/schema", Boolean.valueOf(isValidating));
            factory.setAttribute("http://apache.org/xml/features/validation/schema-full-checking", Boolean.valueOf(true));
        }

        // Add schema location
        if (isValidating) {
            // Needs to get the version attribute and then set the schema
            // location. For this, get the version by parsing the document
            // without validation
            Document detectDocument = getDocument(url, false, entityResolver);

            // Root element = <persistence>
            Element persistenceRootElement = detectDocument.getDocumentElement();
            String version = XMLUtils.getAttributeValue(persistenceRootElement, "version");

            if ("1.0".equals(version)) {
                factory.setAttribute("http://apache.org/xml/properties/schema/external-schemaLocation",
                        "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd");
            } else if ("2.0".equals(version)) {
                factory.setAttribute("http://apache.org/xml/properties/schema/external-schemaLocation",
                        "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
            } else {
                // This is a required attribute, needs to be set by the user !
                throw new DocumentParserException("Cannot detect the version of the Persistence schema from the URL '" + url
                        + "'");
            }

        }

        // Build a document builder
        DocumentBuilder builder = null;
        try {
            builder = factory.newDocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new DocumentParserException("Cannot build a document builder", e);
        }

        // Error handler (throwing exceptions)
View Full Code Here

    }

    // Due to applet security, can only be invoked by run() thread
    private String readXMLFile() {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db;
            Document doc;
            db = dbf.newDocumentBuilder();
            doc = db.parse(file);
            doc.getDocumentElement().normalize();
            LogIt.log("Root element " + doc.getDocumentElement().getNodeName());
            NodeList nodeList = doc.getElementsByTagName(xmlTag);
            if (nodeList.getLength() > 0) {
View Full Code Here

        }
        gen.exportMethods();
    }

    protected void parse(String inputFilename) throws Exception {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(inputFilename);
        rootElement = doc.getDocumentElement();
    }
View Full Code Here

        }
        gen.exportMethods();
    }

    protected void parse(String inputFilename) throws Exception {
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(inputFilename);
        rootElement = doc.getDocumentElement();
    }
View Full Code Here

   */
  @Test
  @SuppressWarnings("nls")
  public void testW3CDocument() throws Exception {
    InputStream inS = getClass().getResourceAsStream("/data/interpreter/feed_opml.xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = factory.newDocumentBuilder();

    InputSource source = new InputSource(inS);
    org.w3c.dom.Document doc = documentBuilder.parse(source);
    inS.close();

View Full Code Here

    }

    private static Document parseXml(final String xmlString)
            throws ParserConfigurationException, SAXException, IOException {

        final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        final DocumentBuilder db = dbf.newDocumentBuilder();
        final Document doc = db.parse(new ByteArrayInputStream(xmlString
                .getBytes()));
        return doc;
    }
View Full Code Here

    List<ReconfigBeanDefinitionHolder> holders = new ArrayList<ReconfigBeanDefinitionHolder>();
    try {
      InputStream inputStream = resource.getInputStream();
      try {
        InputSource inputSource = new InputSource(inputStream);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = factory.newDocumentBuilder();
        Document doc = docBuilder.parse(inputSource);
        Element root = doc.getDocumentElement();
        NodeList nl = root.getChildNodes();
        BeanDefinitionParser parser = new BeanDefinitionParser();
        for (int i = 0; i < nl.getLength(); i++) {
View Full Code Here

    private static Document getDocument( final String resource ) throws Exception
    {
        Document retVal = null;
        try
        {
            final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            builderFactory.setNamespaceAware( true );
            builderFactory.setIgnoringComments( true );
            final DocumentBuilder builder = builderFactory.newDocumentBuilder();
            retVal = builder.parse( Main.class.getResourceAsStream( resource ) );
        }
        catch ( ParserConfigurationException e )
        {
            e.printStackTrace( System.err );
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.