Package org.w3c.dom

Examples of org.w3c.dom.DOMConfiguration


     * Note: This is a hint, and may be ignored by DOM implemenations.
     *
     * @param pPrettyPrint {@code true} to enable pretty printing
     */
    public void setPrettyPrint(final boolean pPrettyPrint) {
        DOMConfiguration configuration = serializer.getDomConfig();
        if (configuration.canSetParameter(PARAM_PRETTY_PRINT, pPrettyPrint)) {
            configuration.setParameter(PARAM_PRETTY_PRINT, pPrettyPrint);
        }
    }
View Full Code Here


     * @return A <code>LSSerializer</code> instance
     * @see <a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/">DOM Level 3 Load and Save Specification</a>
     */
    public static LSSerializer createLSSerializer(DOMImplementationLS impl, boolean includeXmlDeclaration, boolean enablePrettyPrint) {
        LSSerializer writer = impl.createLSSerializer();
        DOMConfiguration domConfig = writer.getDomConfig();
        domConfig.setParameter("xml-declaration", includeXmlDeclaration);
        domConfig.setParameter("format-pretty-print", enablePrettyPrint);
        return writer;
    }
View Full Code Here

            XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");

            XSLoader schemaLoader = impl.createXSLoader(null);

            DOMConfiguration config = schemaLoader.getConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new QueryXS();

            // set error handler
            config.setParameter("error-handler", errorHandler);

            // set validation feature
            config.setParameter("validate", Boolean.TRUE);

            // parse document
            System.out.println("Parsing " + argv[0] + "...");
            XSModel model = schemaLoader.loadURI(argv[0]);
            if (model != null) {
View Full Code Here

                (DOMImplementationLS)registry.getDOMImplementation("LS");

            // create DOMBuilder
            builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
           
            DOMConfiguration config = builder.getDomConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new DOM3();
           
            // create filter
            LSParserFilter filter = new DOM3();
           
            builder.setFilter(filter);

            // set error handler
            config.setParameter("error-handler", errorHandler);


            // set validation feature
            //config.setParameter("validate", Boolean.FALSE);
            config.setParameter("validate",Boolean.TRUE);
           
            // set schema language
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("psvi",Boolean.TRUE);
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
           
            // set schema location
            config.setParameter("schema-location","personal.xsd");
           
            // parse document
            System.out.println("Parsing "+argv[0]+"...");
            Document doc = builder.parseURI(argv[0]);

            // set error handler on the Document
            config = doc.getDomConfig();
           
            config.setParameter("error-handler", errorHandler);

            // set validation feature
            config.setParameter("validate", Boolean.TRUE);
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
            config.setParameter("schema-location","data/personal.xsd");
           
            // remove comments from the document
            config.setParameter("comments", Boolean.FALSE);

            System.out.println("Normalizing document... ");
            doc.normalizeDocument();


            // create DOMWriter
            LSSerializer domWriter = impl.createLSSerializer();
           
            System.out.println("Serializing document... ");
            config = domWriter.getDomConfig();
            config.setParameter("xml-declaration", Boolean.FALSE);
            //config.setParameter("validate",errorHandler);

            // serialize document to standard output
            //domWriter.writeNode(System.out, doc);
            LSOutput dOut = impl.createLSOutput();
View Full Code Here

            XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");

            XSLoader schemaLoader = impl.createXSLoader(null);

            DOMConfiguration config = schemaLoader.getConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new QueryXS();

            // set error handler
            config.setParameter("error-handler", errorHandler);

            // set validation feature
            config.setParameter("validate", Boolean.TRUE);

            // parse document
            System.out.println("Parsing " + argv[0] + "...");
            XSModel model = schemaLoader.loadURI(argv[0]);
            if (model != null) {
View Full Code Here

        Handler h = new Handler();
        TestReport report = null;

        // cdata-sections == false
        Document doc = newSVGDoc();
        DOMConfiguration conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("cdata-sections", Boolean.FALSE);
        Element e = doc.getDocumentElement();
        e.appendChild(doc.createTextNode("abc"));
        e.appendChild(doc.createCDATASection("def"));
        e.appendChild(doc.createTextNode("ghi"));
        ((AbstractDocument) doc).normalizeDocument();
        if (!(e.getFirstChild().getNodeType() == Node.TEXT_NODE
                && e.getFirstChild().getNodeValue().equals("abcdefghi")
                && e.getFirstChild() == e.getLastChild())) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "cdata-sections == false");
        }

        // comments == false
        doc = newSVGDoc();
        conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("comments", Boolean.FALSE);
        e = doc.getDocumentElement();
        e.appendChild(doc.createTextNode("abc"));
        e.appendChild(doc.createComment("def"));
        e.appendChild(doc.createTextNode("ghi"));
        ((AbstractDocument) doc).normalizeDocument();
        if (!(e.getFirstChild().getNodeType() == Node.TEXT_NODE
                && e.getFirstChild().getNodeValue().equals("abcghi")
                && e.getFirstChild() == e.getLastChild())) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "comments == false");
        }

        // element-content-whitespace == false
        doc = newSVGDoc();
        conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("element-content-whitespace", Boolean.FALSE);
        e = doc.getDocumentElement();
        e.appendChild(doc.createTextNode("    "));
        e.appendChild(doc.createElementNS(SVG_NAMESPACE_URI, "g"));
        e.appendChild(doc.createTextNode("    "));
        ((AbstractDocument) doc).normalizeDocument();
        if (!(e.getFirstChild().getNodeType() == Node.ELEMENT_NODE
                && e.getFirstChild().getNodeName().equals("g")
                && e.getFirstChild() == e.getLastChild())) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "element-content-whitespace == false");
        }

        // split-cdata-sections == true
        doc = newSVGDoc();
        conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("split-cdata-sections", Boolean.TRUE);
        conf.setParameter("error-handler", h);
        e = doc.getDocumentElement();
        e.appendChild(doc.createCDATASection("before ]]> after"));
        ((AbstractDocument) doc).normalizeDocument();
        if (!(e.getFirstChild().getNodeType() == Node.CDATA_SECTION_NODE
                && e.getFirstChild().getNodeValue().equals("before ]]")
                && e.getFirstChild().getNextSibling().getNodeType() == Node.CDATA_SECTION_NODE
                && e.getFirstChild().getNextSibling().getNodeValue().equals("> after")
                && e.getFirstChild().getNextSibling() == e.getLastChild()
                && h.get("cdata-sections-splitted") == 1)) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "split-cdata-sections == true");
        }

        // well-formed
        doc = newSVGDoc();
        ((AbstractDocument) doc).setStrictErrorChecking(false);
        conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("error-handler", h);
        e = doc.getDocumentElement();
        e.appendChild(doc.createComment("before -- after"));
        e.appendChild(doc.createComment("ends in a dash -"));
        e.setAttribute("*", "blah");
        e.appendChild(doc.createProcessingInstruction("abc", "def?>"));
        ((AbstractDocument) doc).normalizeDocument();
        if (!(h.get("wf-invalid-character-in-node-name") == 1
                && h.get("wf-invalid-character") == 3)) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "well-formed == true");
        }

        // namespaces
        doc = newDoc();
        e = doc.createElementNS(null, "root");
        doc.appendChild(e);
        Element e2 = doc.createElementNS(null, "parent");
        e.appendChild(e2);
        e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns1");
        e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:bar", "http://www.example.org/ns2");
        Element e3 = doc.createElementNS("http://www.example.org/ns1", "ns:child1");
        e2.appendChild(e3);
        e3.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns2");
        e3 = doc.createElementNS("http://www.example.org/ns2", "ns:child2");
        e2.appendChild(e3);
        ((AbstractDocument) doc).normalizeDocument();
        Attr a = e3.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns");
        if (!(a != null
                    && a.getNodeName().equals("xmlns:ns")
                    && a.getNodeValue().equals("http://www.example.org/ns2"))) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 1");
        }

        doc = newDoc();
        e = doc.createElementNS(null, "root");
        doc.appendChild(e);
        e2 = doc.createElementNS("http://www.example.org/ns1", "ns:child1");
        e.appendChild(e2);
        e2.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ns", "http://www.example.org/ns1");
        e3 = doc.createElementNS("http://www.example.org/ns1", "ns:child2");
        e2.appendChild(e3);
        e2 = (Element) ((AbstractDocument) doc).renameNode(e2, "http://www.example.org/ns2", "ns:child1");
        ((AbstractDocument) doc).normalizeDocument();
        a = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns");
        Attr a2 = e3.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ns");
        if (!(a != null
                    && a.getNodeName().equals("xmlns:ns")
                    && a.getNodeValue().equals("http://www.example.org/ns2")
                    && a2 != null
                    && a2.getNodeName().equals("xmlns:ns")
                    && a2.getNodeValue().equals("http://www.example.org/ns1"))) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 2");
        }

        doc = newDoc();
        e = doc.createElementNS(null, "root");
        doc.appendChild(e);
        e2 = doc.createElementNS("http://www.example.org/ns1", "child1");
        e.appendChild(e2);
        e2.setAttributeNS("http://www.example.org/ns2", "blah", "hi");
        ((AbstractDocument) doc).normalizeDocument();
        a = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "xmlns");
        a2 = e2.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "NS1");
        if (!(a != null
                    && a.getNodeValue().equals("http://www.example.org/ns1")
                    && a2 != null
                    && a2.getNodeValue().equals("http://www.example.org/ns2"))) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
            }
            report.addDescriptionEntry("DOMConfiguration parameter", "namespaces == true, test 3");
        }

        // namespace-declarations == false
        doc = newDoc();
        e = doc.createElementNS(null, "ex:root");
        e.setAttributeNS(XMLNS_NAMESPACE_URI, "xmlns:ex", "http://www.example.org/ns1");
        conf = ((AbstractDocument) doc).getDomConfig();
        conf.setParameter("namespace-declarations", Boolean.FALSE);
        doc.appendChild(e);
        ((AbstractDocument) doc).normalizeDocument();
        if (!(e.getAttributeNodeNS(XMLNS_NAMESPACE_URI, "ex") == null)) {
            if (report == null) {
                report = reportError("Document.normalizeDocument test failed");
View Full Code Here

            }
        });
       
       
        if (serializerParams != null) {
            DOMConfiguration serializerDOMConfig = serializer.getDomConfig();
            for (String key : serializerParams.keySet()) {
                serializerDOMConfig.setParameter(key, serializerParams.get(key));
            }
        }
       
        return serializer;
    }
View Full Code Here

                (DOMImplementationLS)registry.getDOMImplementation("LS-Load");

            // create DOMBuilder
            builder = impl.createDOMBuilder(DOMImplementationLS.MODE_SYNCHRONOUS, null);
           
            DOMConfiguration config = builder.getConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new DOM3();
           
            // create filter
            DOMBuilderFilter filter = new DOM3();
           
            builder.setFilter(filter);

            // set error handler
            config.setParameter("error-handler", errorHandler);


            // set validation feature
            //config.setParameter("validate", Boolean.FALSE);
            config.setParameter("validate",Boolean.TRUE);
           
            // set schema language
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("psvi",Boolean.TRUE);
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
           
            // set schema location
            config.setParameter("schema-location","personal.xsd");
           
            // parse document
            System.out.println("Parsing "+argv[0]+"...");
            Document doc = builder.parseURI(argv[0]);

            // set error handler on the Document
            config = doc.getConfig();
           
            config.setParameter("error-handler", errorHandler);

            // set validation feature
            config.setParameter("validate", Boolean.TRUE);
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
            config.setParameter("schema-location","data/personal.xsd");
           
            // remove comments from the document
            config.setParameter("comments", Boolean.FALSE);

            System.out.println("Normalizing document... ");
            doc.normalizeDocument();


            // create DOMWriter
            DOMWriter domWriter = impl.createDOMWriter();
           
            System.out.println("Serializing document... ");
            config = domWriter.getConfig();
            config.setParameter("xml-declaration", Boolean.FALSE);
            //config.setParameter("validate",errorHandler);

            // serialize document to standard output
            domWriter.writeNode(System.out, doc);
View Full Code Here

                (DOMImplementationLS)registry.getDOMImplementation("LS");

            // create DOMBuilder
            builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
           
            DOMConfiguration config = builder.getDomConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new DOM3();
           
            // create filter
            LSParserFilter filter = new DOM3();
           
            builder.setFilter(filter);

            // set error handler
            config.setParameter("error-handler", errorHandler);


            // set validation feature
            //config.setParameter("validate", Boolean.FALSE);
            config.setParameter("validate",Boolean.TRUE);
           
            // set schema language
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("psvi",Boolean.TRUE);
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
           
            // set schema location
            config.setParameter("schema-location","personal.xsd");
           
            // parse document
            System.out.println("Parsing "+argv[0]+"...");
            Document doc = builder.parseURI(argv[0]);

            // set error handler on the Document
            config = doc.getDomConfig();
           
            config.setParameter("error-handler", errorHandler);

            // set validation feature
            config.setParameter("validate", Boolean.TRUE);
            config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
            //config.setParameter("schema-type","http://www.w3.org/TR/REC-xml");
            config.setParameter("schema-location","data/personal.xsd");
           
            // remove comments from the document
            config.setParameter("comments", Boolean.FALSE);

            System.out.println("Normalizing document... ");
            doc.normalizeDocument();


            // create DOMWriter
            LSSerializer domWriter = impl.createLSSerializer();
           
            System.out.println("Serializing document... ");
            config = domWriter.getDomConfig();
            config.setParameter("xml-declaration", Boolean.FALSE);
            //config.setParameter("validate",errorHandler);

            // serialize document to standard output
            //domWriter.writeNode(System.out, doc);
            LSOutput dOut = new DOMOutputImpl();
View Full Code Here

  }
 
  private static Document parse(LSInput input, boolean validateIfSchema) {
    DOMImplementationLS impl = getDOMImpl();
    LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null);
    DOMConfiguration config = parser.getDomConfig();
    config.setParameter("element-content-whitespace", false);
    config.setParameter("namespaces", true);
    config.setParameter("validate-if-schema", validateIfSchema);
    return parser.parse(input);
 
View Full Code Here

TOP

Related Classes of org.w3c.dom.DOMConfiguration

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.