Java Code Examples for org.apache.xml.serialize.OutputFormat#setOmitXMLDeclaration()

The following examples show how to use org.apache.xml.serialize.OutputFormat#setOmitXMLDeclaration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XMLUtils.java    From jdal with Apache License 2.0 6 votes vote down vote up
/**
 * Serialize a Document to a String using JAXP with identation (4 spaces) 
 * @param doc to serialize
 * @return xml string
 */
public static String prettyDocumentToString(Document doc) {
	StringWriter writer = new StringWriter();
	OutputFormat out = new OutputFormat();
	out.setOmitXMLDeclaration(true);
	out.setIndenting(true);
	out.setIndent(4);
	out.setLineSeparator(System.getProperty("line.separator"));
	out.setLineWidth(Integer.MAX_VALUE);
	
	XMLSerializer serializer = new XMLSerializer(writer, out);
	try {
		Element rootElement = doc.getDocumentElement();
		serializer.serialize(rootElement);
	} catch (IOException e) { 
		log.error(e);
	}
	return writer.toString();
}
 
Example 2
Source File: PackageManagerTest.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
    OutputFormat of = new OutputFormat();
    of.setPreserveSpace(true);
    of.setOmitXMLDeclaration(true);
    XMLSerializer tmpSerial = new XMLSerializer(st, of);
    return new SimpleContentHandler(tmpSerial);
}
 
Example 3
Source File: RepomdWriter.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
    OutputFormat of = new OutputFormat();
    of.setPreserveSpace(true);
    of.setOmitXMLDeclaration(true);
    XMLSerializer tmpSerial = new XMLSerializer(st, of);
    SimpleContentHandler tmpHandler = new SimpleContentHandler(tmpSerial);
    return tmpHandler;
}
 
Example 4
Source File: PackageManagerTest.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
    OutputFormat of = new OutputFormat();
    of.setPreserveSpace(true);
    of.setOmitXMLDeclaration(true);
    XMLSerializer tmpSerial = new XMLSerializer(st, of);
    return new SimpleContentHandler(tmpSerial);
}
 
Example 5
Source File: RepomdWriter.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
protected SimpleContentHandler getTemporaryHandler(OutputStream st) {
    OutputFormat of = new OutputFormat();
    of.setPreserveSpace(true);
    of.setOmitXMLDeclaration(true);
    XMLSerializer tmpSerial = new XMLSerializer(st, of);
    SimpleContentHandler tmpHandler = new SimpleContentHandler(tmpSerial);
    return tmpHandler;
}
 
Example 6
Source File: XMLUtils.java    From jdal with Apache License 2.0 5 votes vote down vote up
/** 
 * Element to String without format
 * 
 * @param elto to serialize
 * @return serialized elto
 */
public static String elementToString(Element elto) {
	StringWriter writer = new StringWriter();
	OutputFormat of = new OutputFormat();
	of.setOmitXMLDeclaration(true);
	XMLSerializer serializer = new XMLSerializer(writer, of);
	serializer.setNamespaces(true);
	try {
		serializer.serialize(elto);
	} catch (IOException ioe) {
		log.error(ioe);
	}
	return writer.toString();
}