Hi

here you go:

static public String
dumpToString(org.dom4j.Document doc)
{
         try {
             String encoding = doc.getXMLEncoding();

             if (encoding == null)
                 encoding = "UTF-8";

             Writer osw = new StringWriter();
             OutputFormat opf = new OutputFormat("  ", true, encoding);
             XMLWriter writer = new XMLWriter(osw, opf);
             writer.write(doc);
             writer.close();
             return osw.toString();
         } catch (IOException e) {
             _log.error("failed to write XML to string", e);
         }
         return "ERROR";
     }


Am 17.01.2007 um 00:07 schrieb S. Sharif:
>
> Hi,
> I am trying to output the Document object using a
> log4j output debug statement as follows:
>
>
> // Create xml response document
> Document responseDoc = loadResource();
>
> // log4j debug output statement
> logger.debug(responseDoc.asXML());
>
>
> But the xml output is not nicely formatted.  Is there
> anyway I can return a nicely formatted xml string from
> a dom4j Document object?
>
> I have already looked at the example provided in the
> FAQ page for "How can I pretty print my XML document?"
>
> http://www.dom4j.org/faq.html#pretty-print
>
> But that only shows how to write the Document,  nicely
> formatted, to a writter.  What I need is to return the
> Document, nicely formatted, as a String.
>
> Thanks.
>
>
>
> **********************************************************
> * Saladin Sharif
> * e-mail:  [EMAIL PROTECTED]
> * Visit homepage @ http://gaia.ecs.csus.edu/~sharifs
> **********************************************************
>
>
>
>
> ______________________________________________________________________ 
> ______________
> Need Mail bonding?
> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
> http://answers.yahoo.com/dir/?link=list&sid=396546091
>
> ---------------------------------------------------------------------- 
> ---
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to  
> share your
> opinions on IT & business topics through brief surveys - and earn cash
> http://www.techsay.com/default.php? 
> page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> dom4j-user mailing list
> dom4j-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/dom4j-user




-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-user mailing list
dom4j-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to