if (node == null) {
return null;
}
try {
Document doc = node.getOwnerDocument();
OutputFormat format;
if (doc != null) {
format = new OutputFormat(doc, null, prettyPrint);
} else {
format = new OutputFormat("xml", null, prettyPrint);
}
if (prettyPrint) {
format.setLineSeparator(LINE_SEP);
} else {
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;
return text.getData();
} else if (node instanceof Attr) {