Refine search
success: function(data){ //data.xml check for IE var xmlstr = data.xml ? data.xml : (new XMLSerializer()).serializeToString(data); alert(xmlstr); }
private static XMLSerializer getXMLSerializer(final OutputStream os, final String[] cdataElements) throws InstantiationException, IllegalAccessException, ClassNotFoundException { // configure an OutputFormat to handle CDATA final OutputFormat of = new OutputFormat(); // specify which of your elements you want to be handled as CDATA. // The use of the '^' between the namespaceURI and the localname // seems to be an implementation detail of the xerces code. // When processing xml that doesn't use namespaces, simply omit the // namespace prefix as shown in the third CDataElement below. of.setCDataElements(cdataElements); // set any other options you'd like of.setPreserveSpace(true); of.setIndenting(true); // create the serializer final XMLSerializer serializer = new XMLSerializer(of); serializer.setOutputByteStream(os); return serializer; }
/** * @deprecated relies on XMLSerializer which is a deprecated Xerces class, use domToString instead */ static public String prettyPrint(Element e) throws IOException { OutputFormat format = new OutputFormat(e.getOwnerDocument()); format.setLineWidth(65); format.setIndenting(true); format.setIndent(2); StringWriter out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(e); return out.toString(); }
//Serialize DOM OutputFormat format = new OutputFormat (doc); // as a String StringWriter stringOut = new StringWriter (); XMLSerializer serial = new XMLSerializer (stringOut,format); serial.serialize(doc); // Display the XML System.out.println(stringOut.toString());
/** * Serializes element. * * @param n a DOM element. * @return the serialized element. */ public static String serialize(Element n) { String value = null; try { StringWriter writer = new StringWriter(); XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", "UTF-8", true)); s.serialize(n); value = writer.toString(); writer.close(); } catch (Throwable t) { // nothing value = "EXCEPTION : " + t.getMessage(); } return value; }
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); }
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); } } }
*/ /** * Serializes the specified element. * @param oElt - The element to serialize * @param oFormat - The output format to use */ public static String toString(Element oElt, OutputFormat oFormat) { StringWriter oWriter = new StringWriter(); XMLSerializer oSerialize = new XMLSerializer(oWriter, oFormat); try { oSerialize.serialize(oElt); } catch (java.io.IOException ioe) { throw new RuntimeException( "Problem serializing the XML document:\n" + ioe.getMessage()); } return oWriter.toString(); } // toString()
OutputFormat format; if (doc != null) { format = new OutputFormat(doc, null, prettyPrint); } else { format = new OutputFormat("xml", null, prettyPrint); format.setLineWidth(0); // don't wrap lines format.setLineSeparator(""); StringWriter writer = new StringWriter(1000); XMLSerializer serial = new XMLSerializer(writer, format); serial.asDOMSerializer(); if (node instanceof Document) { serial.serialize((Document) node); } else if (node instanceof Element) { format.setOmitXMLDeclaration(true); serial.serialize((Element) node); } else if (node instanceof DocumentFragment) { format.setOmitXMLDeclaration(true); serial.serialize((DocumentFragment) node); } else if (node instanceof Text) { Text text = (Text) node;
import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.XMLSerializer; public String parseToString(Element node) throws Exception { OutputFormat format = new OutputFormat(); java.io.Writer stringOut = new StringWriter(); XMLSerializer serial = new XMLSerializer(stringOut,format); serial.serialize(node); return stringOut.toString(); }
/** * Represents a document as a string. * @param aDoc * @return the document serialized out as a human-readable String */ public static String toString (Document aDoc) { StringWriter sw = new StringWriter(); try { /* TODO: This should be reviewed at some point to see if we can use the * DOM3 LS capability and hence a standard way of doing this rather * than using an internal implementation class. */ OutputFormat format = new OutputFormat(); format.setOmitXMLDeclaration(true); format.setIndenting(true); XMLSerializer serial = new XMLSerializer(sw, format); serial.serialize(aDoc); } catch (Exception e) { Utility.logMessage("ERROR", "Utility::asString(): " + e, e); } return sw.toString(); }
public static void writeXml(Element element, Writer out, int indent) throws IOException { OutputFormat format = new OutputFormat("XML", "UTF-8", false); format.setOmitComments(false); if (indent > 0) { format.setIndenting(true); format.setIndent(indent); } format.setLineWidth(0); XMLSerializer serializer = new XMLSerializer(format); serializer.setOutputCharStream(out); serializer.serialize(element); }
public OutputStream write() { XMLConf xmlConfig = createXMLConfiguration(); OutputStream out = new ByteArrayOutputStream(); try { XMLSerializer serializer = new XMLSerializer(out, createOutputFormat()); serializer.serialize(xmlConfig.getDocument()); out.close(); } catch (IOException e) { throw new RuntimeException(e); } return out; }
/** * Serializes document. * * @param doc an org.w3c.dom.Document object. * @param writer a java.io.Writer object. * @throws Exception if unable to serialize the document. */ public static void serializeDoc(Document doc, Writer writer) throws java.lang.Exception { XMLSerializer s = new XMLSerializer(writer, new OutputFormat("xml", "UTF-8", true)); s.serialize(doc); }
private void writeDocument(Document document, OutputStream out) throws IOException { XMLSerializer serializer = new XMLSerializer(out, new OutputFormat(document, null, true)); serializer.serialize(document); }
public static void writeXml(Element element, OutputStream os) throws IOException { OutputFormat format = new OutputFormat("XML", "UTF-8", false); format.setOmitComments(false); format.setLineWidth(0); XMLSerializer serializer = new XMLSerializer(format); serializer.setOutputByteStream(os); serializer.serialize(element); }
default void printDocument(Document doc) throws Exception { OutputFormat format = new OutputFormat(doc); format.setIndenting(true); XMLSerializer serializer = new XMLSerializer(System.out, format); serializer.serialize(doc); }
private XMLSerializer createXMLSerializer(Node node, Format fmt) { if(fmt==null) { fmt = Format.defaultFormat; } OutputFormat format = new OutputFormat(); //node.getOwnerDocument()); format.setIndent(fmt.indent); format.setOmitXMLDeclaration(!fmt.xmlDecl); format.setEncoding(fmt.encoding); return new XMLSerializer(format); }
/** * @param doc DOM Document * @throws IOException */ @SuppressWarnings("deprecation") public static void serializeDoc(Document doc) throws IOException { org.apache.xml.serialize.XMLSerializer serializer = new org.apache.xml.serialize.XMLSerializer(); serializer.setOutputByteStream(System.out); serializer.serialize(doc); }
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(); } }