Package org.w3c.dom

Examples of org.w3c.dom.DOMConfiguration


            System.setProperty(DOMImplementationRegistry.PROPERTY,
                    "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader");
            XSLoader schemaLoader = impl.createXSLoader(null);
            DOMConfiguration domConfig = schemaLoader.getConfig();

            // create Error Handler
            DOMErrorHandler errorHandler = new Generator(config);
            domConfig.setParameter("error-handler", errorHandler);
            domConfig.setParameter("validate", Boolean.TRUE);

            // parse document
            String input = config.getInputFile();
            if (input == null || input.length() == 0) {
                System.err.println("No input file!");
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

                }
            }
            if (domImplementationLS != null) {
                final LSSerializer lsSerializer = domImplementationLS
                        .createLSSerializer();
                final DOMConfiguration domConfiguration = lsSerializer
                        .getDomConfig();
                if (domConfiguration.canSetParameter("format-pretty-print",
                        Boolean.TRUE)) {
                    lsSerializer.getDomConfig().setParameter(
                            "format-pretty-print", Boolean.TRUE);
                    final LSOutput lsOutput = domImplementationLS
                            .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

  private void write(Document doc, OutputStream out, boolean close) throws IOException {
    try {
      DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation().getFeature( "LS", "3.0" );
      LSSerializer serializer = ls.createLSSerializer();
      DOMConfiguration domConfig = serializer.getDomConfig();
      trySetPrettyPrint( domConfig );

      LSOutput lsOutput = ls.createLSOutput();
      lsOutput.setEncoding( "UTF-8" );
      lsOutput.setByteStream( out );
View Full Code Here

    }

    static void prettyPrintWithDOM3LS(Document document, OutputStream out) {
        DOMImplementationLS domImpl = getDOMImplementationLS(document);
        LSSerializer lsSerializer = domImpl.createLSSerializer();
        DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
        if (domConfiguration.canSetParameter("format-pretty-print",
                                             Boolean.TRUE)) {
            lsSerializer.getDomConfig().setParameter("format-pretty-print",
                                                     Boolean.TRUE);
            LSOutput lsOutput = domImpl.createLSOutput();
            lsOutput.setEncoding("UTF-8");
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

        config.setParameter("validate-if-schema", validateIfSchema);
        return parser.parse(input);
    }

    public static void validate(Document d, String schema, DOMErrorHandler handler) {
        DOMConfiguration config = d.getDomConfig();
        config.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema");
        config.setParameter("validate", true);
        config.setParameter("schema-location", schema);
        config.setParameter("resource-resolver", new ClasspathResourceResolver());
        config.setParameter("error-handler", handler);
        d.normalizeDocument();
    }
View Full Code Here

    public static String serialize(Document document, boolean prettyPrint) {
        DOMImplementationLS impl = getDOMImpl();
        LSSerializer serializer = impl.createLSSerializer();
        // document.normalizeDocument();
        DOMConfiguration config = serializer.getDomConfig();
        if (prettyPrint && config.canSetParameter("format-pretty-print", Boolean.TRUE)) {
            config.setParameter("format-pretty-print", true);
        }
        config.setParameter("xml-declaration", true);       
        LSOutput output = impl.createLSOutput();
        output.setEncoding("UTF-8");
        Writer writer = new StringWriter();
        output.setCharacterStream(writer);
        serializer.write(document, output);
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.