Hi Christian Agreed about the encoding.
So you want the XMLWriter to only output a certain depth of children and then trim the rest? FWIW you could probably do this pretty easily with an XSLT stylesheet or SAX XMLFilter. Or derive from XMLWriter to add this logic. James ----- Original Message ----- From: "Christian Holmqvist, IT, Posten" <[EMAIL PROTECTED]> To: "'James Strachan'" <[EMAIL PROTECTED]>; "Christian Holmqvist, IT, Posten" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, April 24, 2002 11:17 AM Subject: SV: [dom4j-user] Formatting of 'asXML()' result + and dept limitation? Hi Ofcourse StringWriter is faster, but don't support encoding that could be useful. Well it all depends on what the purpose is. Another matter on the same topic, is it possible to limit the dept with the OutputFormater... that is how many child levels that is outputted. Could be very useful when using outputformater for logging and don't want to clog the log with 10000+++ rows of XML code... but still wants to verify that the XML basic is intact. /Christian > -----Ursprungligt meddelande----- > Fr�n: James Strachan [mailto:[EMAIL PROTECTED]] > Skickat: den 24 april 2002 11:38 > Till: Christian Holmqvist, IT, Posten; > [EMAIL PROTECTED] > �mne: Re: [dom4j-user] Formatting of 'asXML()' result > > > If you want pretty printing then thats the way to do it. You can use a > StringWriter instead which is a bit faster. > > OutputFormat outFormat = OutputFormat.createPrettyPrint(); > outFormat.setEncoding("ISO-8859-1"); > > StringWriter writer = new StringWriter(); > XMLWriter out = new XMLWriter(writer, outFormat); > out.write(newDoc); > String s = writer.toString(); > System.out.println("OUT: " + s); > > > Of course if what you really want to do is output it to a > file or System.out > then you can do that even easier... > > OutputFormat outFormat = OutputFormat.createPrettyPrint(); > outFormat.setEncoding("ISO-8859-1"); > > XMLWriter out = new XMLWriter(System.out, outFormat); > out.write(newDoc); > > James > ----- Original Message ----- > From: "Christian Holmqvist, IT, Posten" > <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Wednesday, April 24, 2002 10:15 AM > Subject: RE: [dom4j-user] Formatting of 'asXML()' result > > > Hi > > If you have the same problem as I have and want to get your > XML code as a > String (if your logging system only handles String logging, > like mine, for > example) I made up a little trick that looks like this. > > (newDoc is a Document) > > OutputFormat outFormat = OutputFormat.createPrettyPrint(); > outFormat.setEncoding("ISO-8859-1"); > ByteArrayOutputStream bao = new ByteArrayOutputStream(); > XMLWriter out = new XMLWriter(bao, outFormat); > out.write(newDoc); > String s = bao.toString(); > System.out.println("OUT: " + s); > > Cheers Christian > P.s. There might be a easier way to get the Document nicely > printed into a > String but I could not find it.... D.s. > > > > > -----Ursprungligt meddelande----- > > Fr�n: Joshua Paech [mailto:[EMAIL PROTECTED]] > > Skickat: den 24 april 2002 03:17 > > Till: [EMAIL PROTECTED] > > �mne: [dom4j-user] Formatting of 'asXML()' result > > > > > > I want to print out particular dom4j Elements containing a > > few attributes > > plus some text. If I do an element.asXML(), the String > > returned is all one > > line. Is it possible to get newlines inserted between each > attribute? > > > > _______________________________________________ > > dom4j-user mailing list > > [EMAIL PROTECTED] > > https://lists.sourceforge.net/lists/listinfo/dom4j-user > > > > _______________________________________________ > dom4j-user mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/dom4j-user > > > > _________________________________________________________ > > Do You Yahoo!? > > Get your free @yahoo.com address at http://mail.yahoo.com > > > _________________________________________________________ Do You Yahoo!? Get your free @yahoo.com address at http://mail.yahoo.com _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
