Running some more tests early in the morning here. I've managed to narrow the problem down specifically to the XMLWriter class.
I've rewritten my code so that instead of using XMLWriter to write my DOM4J document out to a file, I use the document.asXML() method to simply produce a String object. I then create an ordinary FileWriter, and write out the String. The contents of this file are exactly what they're supposed to be, unlike that written with XMLWriter. I'm primarily using XMLWriter as a pretty printer, but obviously there's some kind of problem here. I'm a bit baffled about this one. Rob ----- Original Message ----- From: "Robert J. Lebowitz" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, February 25, 2002 7:34 PM Subject: [dom4j-user] Losing text using SAXReader read() method, or XMLWriter.. not sure > I ran some further tests on the text I'm working with, and found some odd > results. > > I found that if used no dom4j code, and used generic JAXP code to parse the > HTML code I was cleaning up using JTidy, and used a subclass of > DefaultHandler (called XMLPrettyPrinter in the code below), none of my > text "disappeared", though I still have some formatting problems with my > pretty printer. > > Example that works: > > SAXParser parser = factory.newSAXParser(); > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > parser.parse(new InputSource(holder.getReader()), new > XMLPrettyPrinter(baos)); > baos.flush(); > baos.close(); > > System.out.println(baos.toString()); > > However, I need to manipulate the XML a bit before printing it out, so I was > using code like this: > > SAXReader reader = new SAXReader(); > Document document = reader.read(in); > > > // manipulate xml here.... > > XMLWriter writer = new XMLWriter( out, format); > writer.write(document); > writer.flush(); > writer.close(); > > Now the xml is all messed up. I even tried just parsing and writing the > xml (commented out all the manipulation), and again, the xml I'm working > with is messed up. I'm trying to figure out why the dom4j code isn't > working here... whole segments of the xml text is just gone after dom4j gets > ahold of it. > > I'm using jdk 1.4 and its endogenous parsers, etc. for my work. I've > attached a sample input XML document that doesn't work with dom4j... using > the second example, I'd expect the xml to be the same coming out, assuming I > don't perform any manipulations. > > Rob > > _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
