I am using standard Java DOM parser to process an xml file-
I have processed it and made changes to the xml document, now I want to view the modified xml.
How do I store the modified XML into a string variable.
For your reference, the code I am using is given below–
str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><config><var-def name=\"initial_no\">3972971</var-def><var-def name=\"webpage\">asdf</var-def><cloudwhile condition=\"${i.toInt() != 500}\" index=\"i\" returnvalue=\"false\" indexstart=\"1\" upperbound=\"500\"><var-def name=\"webpage\" overwrite=\"true\"><cloudwhile condition=\"${i.toInt() != 500}\" index=\"i\" returnvalue=\"false\" indexstart=\"100\" upperbound=\"700\"></cloudwhile><try><body><http url=\"www.google.com/patents/US${initial_no.toInt()+i.toInt()}\"/></body><catch>ERROR- No content found for this patent number.</catch></try></var-def><file action=\"write\" path=\"data/${initial_no.toInt()+i.toInt()}_content.html\"><var name=\"webpage\"/></file></cloudwhile></config>";
InputStream is = new ByteArrayInputStream(str.getBytes("UTF-8"));
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(is);
//some processing..
You can use Transformer API to do what you want: