<p>toXml.</p>

@param document a {@link com.greenpepper.document.Document} object.
@return a {@link java.lang.String} object.
@throws java.io.IOException if any.
2251
public static String toXml(com.greenpepper.document.Document document) throws IOException
	{
		StringWriter sw = new StringWriter();

		XmlReport xmlReport = XmlReport.newInstance("");
		xmlReport.generate( document );
		xmlReport.printTo( sw );

		return sw.toString();
	}
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);
        }
    }
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);
    }
250308
public String docToString(Document node) throws S2SException {
        try {
            DOMSource domSource = new DOMSource(node);
            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 (Exception e) {
            throw new S2SException(e.getMessage(),e);
        }
    }
216363
public String toXml() throws TwiMLException {
        try {
            Document doc = DocumentBuilderFactory
                .newInstance()
                .newDocumentBuilder()
                .newDocument();
            doc.setXmlStandalone(true);
            doc.appendChild(this.buildXmlElement(doc));

            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            transformer.setOutputProperty(OutputKeys.INDENT, "no");
            DOMSource source = new DOMSource(doc);
            StreamResult output = new StreamResult(new StringWriter());
            transformer.transform(source, output);
            return output.getWriter().toString().trim();
        } catch (TransformerException te) {
            throw new TwiMLException("Exception serializing TwiML: " + te.getMessage());
        } catch (Exception e) {
            throw new TwiMLException("Unhandled exception: " + e.getMessage());
        }
    }
239384
private static Element createResultElement(final Document document) {
        final Element ttResponse = document.createElementNS("http://jaxrx.org/", "result");
        ttResponse.setPrefix("jaxrx");
        return ttResponse;
    }
513960
private String genXML(Set nodes) throws IOException {
        Iterator it = nodes.iterator();
        StringBuffer buf = new StringBuffer(1024);
        buf.append(StateHelper.XML_DOC_START);
        buf.append(getSynchInterval());
        buf.append(StateHelper.XML_DOC_START_END);
        while (it.hasNext()) {
            Node n = (Node) it.next();
            buf.append(StateHelper.XML_NODE_TAG_START);
            buf.append(StateHelper.encodeMACAddress(n.getNodeIdentifier()));
            buf.append(StateHelper.XML_NODE_TAG_AFTER_ID);
            buf.append(n.getClockSequence());
            buf.append(StateHelper.XML_NODE_TAG_AFTER_CSEQ);
            buf.append(n.getLastTimestamp());
            buf.append(StateHelper.XML_NODE_TAG_END);
        }
        buf.append(StateHelper.XML_DOC_END);
        return buf.toString();
    }
676837
public static void writeXML(Document xmldocument, OutputStream stream) throws IOException {
		assert xmldocument != null : AssertMessages.notNullParameter(0);
		assert stream != null : AssertMessages.notNullParameter(1);
		writeNode(xmldocument, stream);
	}
1042177
public static String toStr(Document doc, String charset, boolean isPretty) {
		final StringWriter writer = StrUtil.getWriter();
		try {
			write(doc, writer, charset, isPretty ? INDENT_DEFAULT : 0);
		} catch (Exception e) {
			throw new UtilException(e, "Trans xml document to string error!");
		}
		return writer.toString();
	}
635569
public Document doc() throws IOException {
		// if the stream has already been read, use the text format
		InputSource is;
		if (document == null) {
			if (text == null) {
				is = new InputSource(inputStream);
				is.setEncoding(getCharSet().name());
			} else {
				is = new InputSource(new StringReader(text));
			}
			try {
				document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(is);
			} catch (SAXException e) {
				e.printStackTrace();
			} catch (ParserConfigurationException e) {
				e.printStackTrace();
			}
			inputStream.close();
		}
		return document;
	}
133324
@SuppressWarnings("unused")
	public static String convertDomToString( Document doc)  throws CloudException, InternalException{
		try {
			 if(doc == null) return null;
			 StringWriter stw = new StringWriter();
	         Transformer serializer = TransformerFactory.newInstance().newTransformer();
	         serializer.transform(new DOMSource(doc), new StreamResult(stw));
	        if(stw != null){
	        	return stw.toString();
	        }
	        return null;
		} catch (TransformerConfigurationException e) {			
			throw new InternalException(e);
		} catch (TransformerFactoryConfigurationError e) {
			throw new InternalException(e);
		} catch (TransformerException e) {
			throw new InternalException(e);
		}
	}
1238584
public String toXML() {
        StringBuilder sb = new StringBuilder();
        sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
        toXML(sb, 0);
        return sb.toString();
    }
350597
public static XMLDocument create(XMLStreamEventsSync stream) throws XMLException, IOException {
		XMLDocument doc = new XMLDocument();
		do {
			switch (stream.event.type) {
			case DOCTYPE:
				if (doc.docType != null)
					throw new XMLException(stream.getPosition(), "Unexpected element ", "DOCTYPE");
				doc.docType = new XMLDocumentType(doc, stream.event.text.asString(),
					stream.event.publicId != null ? stream.event.publicId.asString() : null,
					stream.event.system != null ? stream.event.system.asString() : null);
				break;
			case START_ELEMENT:
				if (doc.root != null)
					throw new XMLException(stream.getPosition(), "Unexpected element ", stream.event.text.asString());
				doc.root = XMLElement.create(doc, stream);
				break;
			default: break;
			}
			try { stream.next(); }
			catch (EOFException e) {
				break;
			}
		} while (true);
		return doc;
	}
932922
private String toXml(Node node) {
        try {
            Transformer transformer = TransformerFactory.newInstance().newTransformer();
            StreamResult result = new StreamResult(new StringWriter());
            DOMSource source = new DOMSource(node);
            transformer.transform(source, result);
            return result.getWriter().toString();
          } catch(TransformerException ex) {
              throw new IllegalArgumentException("Could not transform "  +node + " to XML", ex);
          }
    }
502489
public String putDocument(Document document) {
		String key = UUID.randomUUID().toString();
		documentMap.put(key, document);
		return key;
	}
829008
public static Element getContentElementByDoc(Document doc) throws Exception {
        ContentExtractor ce = new ContentExtractor(doc);
        return ce.getContentElement();
    }
304497
private InputStream formatRawContent(final Document document) throws IOException {
        final String body = "<h1>" + escapeAndAddLineBreaks(resolveTitle(document)) + "</h1>"
                + "<p>" + escapeAndAddLineBreaks(document.getContent()) + "</p>";

        return IOUtils.toInputStream(body, StandardCharsets.UTF_8);
    }