Java 8 DOMImplementation - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DOMImplementation class.

This code example shows how to use the following methods:createDocument
        String namespaceURI = null;
 
        String qualifiedName = "abc:def";
        doc = (Document) load("staffNS", builder);
        domImpl = doc.getImplementation();
        newDoc = domImpl.createDocument("http://www.w3.org/DOM/Test",
                "dom:doc", docType);
 
        { 
            boolean success = false;
            try { 
                newDoc.createAttributeNS(namespaceURI, qualifiedName);
            } catch (DOMException ex) {
                success = (ex.code == DOMException.NAMESPACE_ERR);
            } 
            assertTrue("documentcreateattributeNS05", success);
        } 
    } 
    public void testCreateAttributeNS6() throws Throwable { 
        Document doc;
6
CodeRank
This code example shows how to use the following methods:getFeature, hasFeature
            final Document document) {
        // Note that the "format-pretty-print" DOM configuration parameter can 
        // only be set in JDK 1.6+. 
        final DOMImplementation domImplementation = document
                .getImplementation();
        if (domImplementation.hasFeature("LS", "3.0")
                && domImplementation.hasFeature("Core", "2.0")) {
            DOMImplementationLS domImplementationLS = null;
            try { 
                domImplementationLS = (DOMImplementationLS) domImplementation
                        .getFeature("LS", "3.0");
            } 
            catch (final NoSuchMethodError nsme) {
                // Fall back to default LS 
                DOMImplementationRegistry registry = null;
                try { 
                    registry = DOMImplementationRegistry.newInstance();
                } 
                catch (final Exception e) {
                    // DOMImplementationRegistry not available. Falling back to 
6
CodeRank
This code example shows how to use the following methods:getFeature, hasFeature
This code example shows how to use the following methods:createDocument
        IIOMetadata meta =
            iw.getDefaultImageMetadata(new ImageTypeSpecifier(img), null);
        DOMImplementationRegistry registry;
        registry = DOMImplementationRegistry.newInstance();
        DOMImplementation impl = registry.getDOMImplementation("XML 3.0");
        Document doc = impl.createDocument(null, format, null);
        Element root, text, entry;
        root = doc.getDocumentElement();
        root.appendChild(text = doc.createElement("Text"));
        text.appendChild(entry = doc.createElement("TextEntry"));
        // keyword isn't #REQUIRED by the standard metadata format. 
        // However, it is required by the PNG format, so we include it here. 
        entry.setAttribute("keyword", "Comment");
        entry.setAttribute("value", "Some demo comment");
        meta.mergeTree(format, root);
    } 
} 
5
CodeRank
This code example shows how to use the following methods:createDocument
This code example shows how to use the following methods:getFeature, hasFeature
public class XMLUtils { 
	private static Logger LOG = LoggerFactory.getLogger(XMLUtils.class); 
 
	public static String lsSerializePretty(Document doc) {		
		DOMImplementation domImplementation = doc.getImplementation();
		if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) {
			DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0");
			LSSerializer lsSerializer = domImplementationLS.createLSSerializer();
			DOMConfiguration domConfiguration = lsSerializer.getDomConfig();
			if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) {
				lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE);
				LSOutput lsOutput = domImplementationLS.createLSOutput();
				lsOutput.setEncoding("UTF-8");
				StringWriter stringWriter = new StringWriter();
				lsOutput.setCharacterStream(stringWriter);
				lsSerializer.write(doc, lsOutput);
				return stringWriter.toString();
			} else { 
				throw new RuntimeException("DOMConfiguration 'format-pretty-print' parameter isn't settable.");
			} 
5
CodeRank
This code example shows how to use the following methods:createDocument
This code example shows how to use the following methods:getFeature, hasFeature
        // Try to get the DOMImplementation from the doc before 
        // defaulting to the sun implementation class (which uses 
        // sun internal xerces classes not found in the ibm jdk). 
        DOMImplementationLS impl = null;
        DOMImplementation docImpl = doc.getImplementation();
        if (docImpl != null && docImpl.hasFeature("LS", "3.0")) {
            impl = (DOMImplementationLS)docImpl.getFeature("LS", "3.0");
        } else { 
            System.setProperty(DOMImplementationRegistry.PROPERTY,
                "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); 
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
        } 
        LSOutput output = impl.createLSOutput();
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        output.setByteStream(byteArrayOutputStream);
        LSSerializer writer = impl.createLSSerializer();
        writer.write(doc, output);
        byte[] buf = byteArrayOutputStream.toByteArray();
        return new ByteArrayInputStream(buf);
5
CodeRank
This code example shows how to use the following methods:getFeature, hasFeature
This code example shows how to use the following methods:getFeature, hasFeature
    private LSInput getLSInput() throws Exception {
        DOMImplementationLS impl;
        DOMImplementation docImpl = builder.getDOMImplementation();
        // Try to get the DOMImplementation from doc first before 
        // defaulting to the sun implementation. 
        if (docImpl != null && docImpl.hasFeature("LS", "3.0")) {
            impl = (DOMImplementationLS)docImpl.getFeature("LS", "3.0");
        } else { 
            DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
            impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
            if (impl == null) {
                System.setProperty(DOMImplementationRegistry.PROPERTY,
                                   "com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl"); 
                registry = DOMImplementationRegistry.newInstance();
                impl = (DOMImplementationLS)registry.getDOMImplementation("LS");
            } 
        } 
        return impl.createLSInput();
    } 
 
5
CodeRank

Related Java 8 DOMImplementation Questions & Answers:

See Code Examples for Java 8 DOMImplementation Methods: