Getting xml DOM source using Apache Xerces Parser
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   haroon_rasheed
Posted On:   Tuesday, September 24, 2002 02:02 AM

Re: Getting xml DOM source using Apache Xerces Parser

Posted By:   Roseanne_Zhang  
Posted On:   Tuesday, September 24, 2002 06:38 AM

If you use jdom, it is that easy:
    
public static String writeDocumentToString(Document doc, int nIndent)
{
XMLOutputter outputter = new XMLOutputter(makeSpaceString(nIndent), true);
outputter.setTextNormalize(true);
return outputter.outputString(doc);
}

The output is the string representation of the Document. Or you can write it to a file by using FileWriter

public static void writeDocument(Document doc, Writer writer, int nIndent)
throws IOException
{
XMLOutputter outputter = new XMLOutputter(makeSpaceString(nIndent), true);
outputter.setTextNormalize(true);
outputter.output(doc, writer);
}


http://www.jdom.org


BTW, jdom uses xerces internally, you can choose use other parser too. It just make your life easier.

About | Sitemap | Contact