Serializes a DOM document
@param doc
@throws CitrusRuntimeException
@return serialized XML string
421890
public static String serialize(Document doc) {
        LSSerializer serializer = configurer.createLSSerializer();

        LSOutput output = configurer.createLSOutput();
        String charset = getTargetCharset(doc).displayName();
        output.setEncoding(charset);

        StringWriter writer = new StringWriter();
        output.setCharacterStream(writer);

        serializer.write(doc, output);

        return writer.toString();
    }
657657
public static String convertXmlDocumentToString(DomDocument document) {
    StringWriter stringWriter = new StringWriter();
    StreamResult result = new StreamResult(stringWriter);
    transformDocumentToXml(document, result);
    return stringWriter.toString();
  }
939120
public String asString(Document doc) {
        try {
            DOMSource domSource = new DOMSource(doc);
            StringWriter writer = new StringWriter();
            StreamResult result = new StreamResult(writer);
            TransformerFactory tf = TransformerFactory.newInstance();
            Transformer transformer = tf.newTransformer();
            transformer.transform(domSource, result);
            return writer.toString();
        } catch (TransformerException e) {
            throw new IllegalStateException(e);
        }
    }
416294
public static byte[] documentToBytes(Map<String, Object> doc) {
        return doc != null ? SerializationUtils.toByteArrayFst(doc) : ArrayUtils.EMPTY_BYTE_ARRAY;
    }
69443
private Document readDocument(byte[] xhtmlData) throws ParserConfigurationException, SAXException, IOException {

        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        docBuilderFactory.setValidating(false);
        docBuilderFactory.setNamespaceAware(true);
        DocumentBuilder docbuilder = docBuilderFactory.newDocumentBuilder();
        // use special entity resolver so we don't fetch the DTDs from w3.org, which would be slow
        docbuilder.setEntityResolver(m_entityResolver);
        Document doc = docbuilder.parse(new ByteArrayInputStream(xhtmlData));
        return doc;
    }
173024
public void writeXmlDocument(Document document, File file) throws IOException {
        try {
            Transformer tr = transformerFactory.newTransformer();
            tr.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
            tr.setOutputProperty(OutputKeys.INDENT, "yes");
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            tr.transform(new DOMSource(document), new StreamResult(fileOutputStream));
            fileOutputStream.close();
        } catch (Exception e) {
            throw new IOException(e.getMessage(), e);
        }
    }
744166
private static void serializeDocToStream(final OutputStream output, final Document doc) throws IOException {
        final OutputFormat format = OutputFormat.createPrettyPrint();
        final XMLWriter writer = new XMLWriter(output, format);
        writer.write(doc);
        writer.flush();
    }
1337601
public static String documentToString(Document xmlDocument) throws IOException {
        String encoding = (xmlDocument.getXmlEncoding() == null) ? "UTF-8" : xmlDocument.getXmlEncoding();
        OutputFormat format = new OutputFormat(xmlDocument);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(2);
        format.setEncoding(encoding);
        try (Writer out = new StringWriter()) {
            XMLSerializer serializer = new XMLSerializer(out, format);
            serializer.serialize(xmlDocument);
            return out.toString();
        }
    }
518800
public static Text[] toTextArray(Document doc, Object o) throws PageException {
	// Node[]
	if (o instanceof Node[]) {
	    Node[] nodes = (Node[]) o;
	    if (_isAllOfSameType(nodes, Node.TEXT_NODE)) return (Text[]) nodes;

	    Text[] textes = new Text[nodes.length];
	    for (int i = 0; i < nodes.length; i++) {
		textes[i] = toText(doc, nodes[i]);
	    }
	    return textes;
	}
	// Collection
	else if (o instanceof Collection) {
	    Collection coll = (Collection) o;
	    Iterator<Object> it = coll.valueIterator();
	    List<Text> textes = new ArrayList<Text>();
	    while (it.hasNext()) {
		textes.add(toText(doc, it.next()));
	    }
	    return textes.toArray(new Text[textes.size()]);
	}
	// Node Map and List
	Node[] nodes = _toNodeArray(doc, o);
	if (nodes != null) return toTextArray(doc, nodes);
	// Single Text Node
	try {
	    return new Text[] { toText(doc, o) };
	}
	catch (ExpressionException e) {
	    throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Text Array");
	}
    }
739406
public static Document toDocument(String xml) throws SAXException {
		try {
			return toDocument(new StringReader(xml));
		} catch (IOException e) {
			//reading from string
			throw new RuntimeException(e);
		}
	}
261645
public Document serialiseToDocument(final Object obj)
	{
		final Document document = DOMUtils.createDocumentBuilder().newDocument();

		serialise(obj, document);

		return document;
	}
981767
public static String xmlToString(Document document) throws Exception {
        if (transformer == null) {
            throw new Exception("Transformer is null");
        }
        Source xmlSource = new DOMSource(document);
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        transformer.transform(xmlSource, result);
        return stringWriter.toString();
    }
408611
public static void serializeXMLDocument (Document doc, Writer output) throws TransformerException {
        // serialize XML document using identity transformation
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(output);
        trans.transform(source, result);
    }
363893
private ContentStream jcrBinaryContent( Document document ) {
        // pickup node properties
        Document props = document.getDocument("properties").getDocument(JcrLexicon.Namespace.URI);

        // extract binary value and content
        Binary value = props.getBinary("data");

        if (value == null) {
            return null;
        }

        byte[] content = value.getBytes();
        String fileName = props.getString("fileName");
        String mimeType = props.getString("mimeType");

        // wrap with input stream
        ByteArrayInputStream bin = new ByteArrayInputStream(content);
        bin.reset();

        // create content stream
        return new ContentStreamImpl(fileName, BigInteger.valueOf(content.length), mimeType, bin);
    }
424278
public static void convertDOMToXML(Node doc, Writer out)
    {
        try {
            // Use a Transformer for output
            TransformerFactory tFactory = TransformerFactory.newInstance();
            Transformer transformer = tFactory.newTransformer();

            DOMSource source = new DOMSource(doc);

            StreamResult result = new StreamResult(out);
            transformer.transform(source, result);
        } catch (TransformerConfigurationException tce) {
            // Error generated by the parser
            tce.printStackTrace();
        } catch (TransformerException te) {
            // Error generated by the parser
            te.printStackTrace();
        }
    }
813247
public static void exportFileToDOM(DocumentBuilder stringdb, BaseTable table, Document doc, Element elRoot)
    {
        try   {
            table.close();
            while (table.hasNext())
            {
            	table.next();
            	Record record = table.getRecord();
                XmlUtilities.createXMLRecord(stringdb, record, doc, elRoot);
            }
            elRoot.appendChild(doc.createTextNode(NEWLINE));
        } catch (DBException ex)    {
            ex.printStackTrace();
            System.exit(0);
        }
    }
369709
public static String convertDocToString(Document doc) throws TransformerException {
        //set up a transformer
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, YES);
        trans.setOutputProperty(OutputKeys.INDENT, YES);

        //create string from xml tree
        StringWriter sw = new StringWriter();
        StreamResult result = new StreamResult(sw);
        DOMSource source = new DOMSource(doc);
        trans.transform(source, result);
        return sw.toString();
    }