1

While parsing an XML, given a Node object, can I retrieve the raw XML that corresponds to that Node? I'm using Java and parsing the XML using JDOM.

1 Answer 1

1

Element.toString() should return a String representation of the Element but you can also use the XMLOutputter for that purpose (for writing the xml to some outputstream):

Element e=document.getRootElement();
XmlOutputter outputter=new XmlOutputter();
outputter.output(e,System.out);

this simple snippet should write the XML of the root element to stdout.

hope that helped..

Sign up to request clarification or add additional context in comments.

1 Comment

hmm thats what I wanted. Element.toString() won't work though. It returns [Element: <question/>] (question being my tag). XMLOutputter does the job. I used outputString(Element element) to get the raw XML as a String.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.