public static void validate( Document doc, String schemaLocationPropertyValue, EntityResolver resolver) throws IOException, SAXException { OutputFormat format = new OutputFormat(doc, null, true); StringWriter writer = new StringWriter(1000); XMLSerializer serial = new XMLSerializer(writer, format); serial.asDOMSerializer(); serial.serialize(doc); String docString = writer.toString(); validate(docString, schemaLocationPropertyValue, resolver); }
serial.asDOMSerializer(); if (node instanceof Document) { serial.serialize((Document) node);
public static void write(DocumentFragment fragment, OutputFormat format, OutputStream out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, format); serializer.asDOMSerializer().serialize(fragment); }
public static void write(Document doc, OutputFormat format, OutputStream out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, format); serializer.asDOMSerializer().serialize(doc); }
/** * Save the stats (called when the parsing of input statistics is * completed). * * @see net.objectlab.qalab.interfaces.QALabExporter#save() */ public final void save() throws IOException { OutputFormat format = new OutputFormat(compiledStats, "UTF-8", true); FileWriter stringOut = new FileWriter(outputFile); if (!XML_VERSION.equals(currentXmlVersion)) { // replace DTD! StringWriter sw = new StringWriter(); XMLSerializer serial = new XMLSerializer(sw, format); serial.asDOMSerializer(); // As a DOM Serializer serial.serialize(compiledStats); sw.flush(); sw.close(); StringBuffer newXml = new StringBuffer(sw.getBuffer().substring(sw.getBuffer().indexOf("<qalab"))); newXml.insert(0, DTD_DEFINITION); stringOut.write(newXml.toString()); } else { XMLSerializer serial = new XMLSerializer(stringOut, format); serial.asDOMSerializer(); // As a DOM Serializer serial.serialize(compiledStats); } stringOut.flush(); stringOut.close(); }
public static void write(Element element, OutputFormat format, OutputStream out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, format); serializer.asDOMSerializer().serialize(element); }
/** * Send Xml response body. * * @param serializable * @param status * @throws IOException * @see DavServletResponse#sendXmlResponse(XmlSerializable, int); */ public void sendXmlResponse(XmlSerializable serializable, int status) throws IOException { httpResponse.setStatus(status); if (serializable != null) { ByteArrayOutputStream out = new ByteArrayOutputStream(); try { Document doc = DomUtil.BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", false); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); byte[] bytes = out.toByteArray(); httpResponse.setContentType("text/xml; charset=UTF-8"); httpResponse.setContentLength(bytes.length); httpResponse.getOutputStream().write(bytes); } catch (ParserConfigurationException e) { log.error(e.getMessage()); throw new IOException(e.getMessage()); } } }
private byte[] addXMLNameSpace(Document xmlDoc, String nameSpace){ Node node = xmlDoc.getDocumentElement(); Element element = (Element)node; element.setAttribute("xmlns", nameSpace); OutputFormat outputFormat = new OutputFormat(xmlDoc); outputFormat.setOmitDocumentType(true); ByteArrayOutputStream out = new ByteArrayOutputStream(); XMLSerializer serializer = new XMLSerializer( out,outputFormat ); try { serializer.asDOMSerializer(); serializer.serialize( xmlDoc.getDocumentElement()); } catch (IOException e) { throw new RuntimeException(e); } return out.toByteArray(); } }
XMLSerializer serializer = new XMLSerializer(w,format); serializer.asDOMSerializer(); serializer.serialize(element); String result = w.toString();
XMLSerializer serializer = new XMLSerializer( out,outputFormat ); try { serializer.asDOMSerializer(); serializer.serialize( xmlDoc.getDocumentElement());
public static String serialize(XmlSerializable serializable) throws IOException { StringWriter out = new StringWriter(); try { Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); return out.toString(); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } } }
public static String serialize(XmlSerializable serializable) throws IOException { StringWriter out = new StringWriter(); try { Document doc = BUILDER_FACTORY.newDocumentBuilder().newDocument(); doc.appendChild(serializable.toXml(doc)); OutputFormat format = new OutputFormat("xml", "UTF-8", true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.setNamespaces(true); serializer.asDOMSerializer().serialize(doc); return out.toString(); } catch (ParserConfigurationException e) { throw new CosmoParseException(e); } } }
XMLSerializer serializer = new XMLSerializer(fos, of); try { serializer.asDOMSerializer(); serializer.serialize(docElement);
public static void writeXmlDocument(OutputStream os, Document document) throws java.io.IOException { if (document == null) { Debug.logWarning("[UtilXml.writeXmlDocument] Document was null, doing nothing", module); return; } if (os == null) { Debug.logWarning("[UtilXml.writeXmlDocument] OutputStream was null, doing nothing", module); return; } // if(document instanceof XmlDocument) { // Crimson writer // XmlDocument xdoc = (XmlDocument) document; // xdoc.write(os); // } // else { // Xerces writer OutputFormat format = new OutputFormat(document); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(os, format); serializer.asDOMSerializer(); serializer.serialize(document.getDocumentElement()); // } }
public static void writeXmlDocument(OutputStream os, Document document) throws java.io.IOException { if (document == null) { Debug.logWarning("[UtilXml.writeXmlDocument] Document was null, doing nothing", module); return; } if (os == null) { Debug.logWarning("[UtilXml.writeXmlDocument] OutputStream was null, doing nothing", module); return; } // if(document instanceof XmlDocument) { // Crimson writer // XmlDocument xdoc = (XmlDocument) document; // xdoc.write(os); // } // else { // Xerces writer OutputFormat format = new OutputFormat(document); format.setIndent(2); XMLSerializer serializer = new XMLSerializer(os, format); serializer.asDOMSerializer(); serializer.serialize(document.getDocumentElement()); // } }