Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within XML
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
XML and Related Technologies
Append New content in previous XML generated using StreamResult
Azrael Noor
Ranch Hand
Posts: 385
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Generating XML Twice
But second time i want to append content to previous XML
How to do that?
present code is this:
static boolean GenerateXML() { try { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); String root = "eMavenError"; String element[] = {"ServiceID", "Pk_ServiceRequest_ID", "Request_ID", "Request_Data", "ErrorDateTime", "ErrorMessage", "ErrorDescription", "ErrorAction"}; String Data[] = {"2", "", "MessageID:1", "OO LA LA LA LA OO LE LO", new Date().toString(), "Your System gone", "it's Gone", "Go and *** yourself. Your system will not get soon"}; DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.newDocument(); Element rootElement = document.createElement(root); document.appendChild(rootElement); rootElement.appendChild(document.createTextNode("\n")); for (int j = 0; j < element.length; j++) { Element em = document.createElement(element[j]); em.appendChild(document.createTextNode(Data[j])); rootElement.appendChild(em); rootElement.appendChild(document.createTextNode("\n")); } TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult("c:\\Tryout.xml"); transformer.transform(source, result); return true; } catch (Exception e) { System.out.println("Unable to Generate XML : " + e.getMessage()); return false; }
If stream result could not be used what could else can be used? (My hand is paining while typing
)
Thank you to Answerres
Regards
Azrael Noor
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Since an XML document can have only one root element, you can't simply append a new serialized DOM to an existing file and get a combined document.
Bill
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
create a xml from getting values from html forms
Appending data to existing XML file
XML content is not forming when running from server
Format problem in XML
How to create XML file programmatically?
More...