/**
* Convert the XML of a string into a Org.w3c.dom.Document object
* @param xml
* @return
*/
public static Document getdocument (String xml) {
Document document = NULL;
try {
Documentbuilderfactory dbf = Documentbuilderfactory.newinstance ();
Documentbuilder db = Dbf.newdocumentbuilder ();
InputStream is = new Bytearrayinputstream (Xml.getbytes ());
Document = Db.parse (IS);
} catch (Exception e) {
E.printstacktrace ();
}
return document;
}
/**
* Writes the Org.w3c.dom.Document object to the specified file
*
* @param doc
* @param fileName
* @throws Exception
*/
private static void Outputxml (Document doc, String fileName) {
try {
Transformerfactory tf = Transformerfactory.newinstance ();
Transformer Transformer = Tf.newtransformer ();
Domsource Source = new Domsource (DOC);
Transformer.setoutputproperty (outputkeys.encoding, "UTF-8");
Transformer.setoutputproperty (outputkeys.indent, "yes");//increment line indent, but indent defaults to 0
Transformer.setoutputproperty ("{Http://xml.apache.org/xslt}indent-amount", "2");//Set Indent to 2
PrintWriter pw = new PrintWriter (new OutputStreamWriter (New FileOutputStream (FileName), "UTF-8"));
Streamresult result = new Streamresult (PW);
Transformer.transform (source, result);
} catch (Exception e) {
E.printstacktrace ();
}
}
String XML generates an XML file