Refine search
private static String prettyFormat(Document document, boolean keepXmlDeclaration) { try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImplementation = (DOMImplementationLS) registry.getDOMImplementation("LS"); Writer stringWriter = new StringWriter(); LSOutput formattedOutput = domImplementation.createLSOutput(); formattedOutput.setCharacterStream(stringWriter); LSSerializer domSerializer = domImplementation.createLSSerializer(); domSerializer.getDomConfig().setParameter("format-pretty-print", true); // Set this to true if the declaration is needed to be in the output. domSerializer.getDomConfig().setParameter("xml-declaration", keepXmlDeclaration); domSerializer.write(document, formattedOutput); return stringWriter.toString(); } catch (Exception e) { throw new RuntimeException(FORMAT_ERROR, e); } }
public DOMSerializer() { super(Node.class); DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new IllegalStateException("Could not instantiate DOMImplementationRegistry: "+e.getMessage(), e); } _domImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); }
private Document getDocument(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSParser parser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); // we need to ignore whitespace here so the nodeToString() method will be able to indent it properly: parser.setFilter(new IgnoreWhitespaceFilter()); LSInput domInput = impl.createLSInput(); domInput.setByteStream(is); return parser.parse(domInput); }
final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); final LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); // Set this to true if the output needs to be beautified. writer.getDomConfig().setParameter("xml-declaration", keepDeclaration); // Set this to true if the declaration is needed to be outputted. return writer.writeToString(document); } catch (Exception e) { throw new RuntimeException(e);
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("XML 3.0 LS 3.0"); if (impl == null) { System.out.println("No DOMImplementation found !"); LSParser parser = impl.createLSParser( DOMImplementationLS.MODE_SYNCHRONOUS, "http://www.w3.org/TR/REC-xml"); LSSerializer serializer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); output.setEncoding("UTF-8"); output.setByteStream(System.out); serializer.write(doc, output); System.out.println();
import org.w3c.dom.bootstrap.DOMImplementationRegistry; import org.w3c.dom.Document; import org.w3c.dom.ls.DOMImplementationLS; import org.w3c.dom.ls.LSSerializer; ... DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); String str = writer.writeToString(node);
/** * Normalize and pretty-print XML so that it can be compared using string * compare. The following code does the following: - Removes comments - * Makes sure attributes are ordered consistently - Trims every element - * Pretty print the document * * @param xml The XML to be normalized * @return The equivalent XML, but now normalized */ public static String normalizeXML(String xml) throws Exception { // Remove all white space adjoining tags ("trim all elements") xml = xml.replaceAll("\\s*<", "<"); xml = xml.replaceAll(">\\s*", ">"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domLS = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSParser lsParser = domLS.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); LSInput input = domLS.createLSInput(); input.setStringData(xml); Document document = lsParser.parse(input); LSSerializer lsSerializer = domLS.createLSSerializer(); lsSerializer.getDomConfig().setParameter("comments", Boolean.FALSE); lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); return lsSerializer.writeToString(document); }
DOMImplementationLS impls = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSOutput domOutput = impls.createLSOutput(); domOutput.setEncoding(java.nio.charset.Charset.defaultCharset().name()); domOutput.setCharacterStream(stringWriter); domOutput.setEncoding(ENCODING); LSSerializer domWriter = impls.createLSSerializer(); DOMConfiguration domConfig = domWriter.getDomConfig(); domConfig.setParameter("format-pretty-print", true); domConfig.setParameter("element-content-whitespace", true); domWriter.setNewLine("\r\n"); domConfig.setParameter("cdata-sections", Boolean.TRUE); domWriter.write(source, domOutput); subscrXML = domOutput.getCharacterStream().toString(); DOMStringList dsl=domConfig.getParameterNames();
/** * Creates a new XMLSerializer object. * @param doc Document to be serialized */ public XMLSerializer(Document doc) { // Store the ref this.doc = doc; // Create the LSSerializer and LSOutput instances DOMImplementationRegistry registry; try { registry = DOMImplementationRegistry.newInstance(); } catch (Exception e) { throw new RuntimeException("Cannot get the system DOMImplementationRegistry", e); } DOMImplementation impl = registry.getDOMImplementation("LS 3.0"); DOMImplementationLS factory = (DOMImplementationLS) impl; // Define the format for the xml document serializer = factory.createLSSerializer(); serializer.setNewLine(DEF_LINE_SEP); output = factory.createLSOutput(); output.setEncoding("UTF-8"); //DOMConfiguration dc = serializer.getDomConfig(); //dc.setParameter("format-pretty-print", Boolean.TRUE); //dc.setParameter("schema-type", "http://www.w3.org/2001/XMLSchema"); }
/** * Runs the test case. * @throws Throwable Any uncaught exception causes test to fail */ public void runTest() throws Throwable { org.w3c.dom.bootstrap.DOMImplementationRegistry domImplRegistry; DOMImplementationList domImplList; int length; domImplRegistry = org.w3c.dom.bootstrap.DOMImplementationRegistry.newInstance(); assertNotNull("domImplRegistryNotNull", domImplRegistry); domImplList = domImplRegistry.getDOMImplementationList(""); length = (int) domImplList.getLength(); assertTrue("atLeastOne", (length > 0)); } /**
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS lsImpl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSSerializer serializer = lsImpl.createLSSerializer(); String nodeString = serializer.writeToString(node);
@Override /* LSResourceResolver */ public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { String schema = schemas.get(namespaceURI); if (schema == null) throw new FormattedRuntimeException("No schema found for namespaceURI ''{0}''", namespaceURI); try { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS domImplementationLS = (DOMImplementationLS)registry.getDOMImplementation("LS 3.0"); LSInput in = domImplementationLS.createLSInput(); in.setCharacterStream(new StringReader(schema)); in.setSystemId(systemId); return in; } catch (Exception e) { throw new RuntimeException(e); } } }
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); registry.addSource(new DOMXSImplementationSourceImpl()); Object xsImplementation = registry.getDOMImplementation("XS-Loader"); if (xsImplementation == null) { throw new ConfigurationException("Failed to retrieve XS-Loader implementation from registry obtained via DOMImplementationRegistry.newInstance, please check that registry.getDOMImplementation(\"XS-Loader\") returns an instance"); schemaLoader.getConfig().setParameter("error-handler", new XSDSchemaMapperErrorHandler(schemaResource)); XSModel xsModel;
"org.apache.xerces.dom.DOMXSImplementationSourceImpl" ); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); XSImplementation impl = (XSImplementation) registry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); DOMConfiguration config = schemaLoader.getConfig(); config.setParameter("error-handler", errorHandler); config.setParameter("validate", Boolean.TRUE); config.setParameter("error-handler", errorHandler); config.setParameter("http://apache.org/xml/properties/internal/entity-resolver", resolver);
public XmlConfigurer() { try { registry = DOMImplementationRegistry.newInstance(); if (log.isDebugEnabled()) { DOMImplementationList domImplList = registry.getDOMImplementationList("LS"); for (int i = 0; i < domImplList.getLength(); i++) { log.debug("Found DOMImplementationLS: " + domImplList.item(i)); } } domImpl = (DOMImplementationLS) registry.getDOMImplementation("LS"); if (log.isDebugEnabled()) { log.debug("Using DOMImplementationLS: " + domImpl.getClass().getName()); } } catch (Exception e) { throw new CitrusRuntimeException(e); } setDefaultParseSettings(); setDefaultSerializeSettings(); }
static DOMImplementationLS getImplementation() { DOMImplementationLS implementation = (DOMImplementationLS) DOM_REGISTRY.getDOMImplementation("LS 3.0"); if (implementation == null) { DOMImplementationList list = DOM_REGISTRY.getDOMImplementationList(""); System.err.println("DOM implementations (" + list.getLength() + "):"); for (int i = 0; i < list.getLength(); i++) { System.err.println(" " + list.item(i)); } throw new IllegalStateException("Could not create DOM Implementation (no LS support found)"); } return implementation; }
private static DOMImplementationRegistry createDOMRegistry() { try { return DOMImplementationRegistry.newInstance(); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } catch (InstantiationException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } } }
System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); com.sun.org.apache.xerces.internal.impl.xs.XSImplementationImpl impl = (XSImplementationImpl) registry.getDOMImplementation("XS-Loader"); XSLoader schemaLoader = impl.createXSLoader(null); XSModel model = schemaLoader.loadURI("src/test/resources/my.xsd");
private LSInput getLSInput(InputStream is) throws InstantiationException, IllegalAccessException, ClassNotFoundException { final DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSInput domInput = impl.createLSInput(); domInput.setByteStream(is); return domInput; }
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS)registry.getDOMImplementation("LS"); LSParser lsParser = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); Document document = lsParser.parseURI("myFile.xml");