How does the \0 get into the String in the first place? This is an invalid XML String which preferably you should filter out before adding it to dom4j. Sure dom4j could check every character of every String that gets added to a document, though it'd add considerable overhead - so I'd prefer this to stay inside your application for now.
Maybe you could make a simple helper method that could filter out any invalid characters from your element and attribute values? James ------- http://radio.weblogs.com/0112098/ ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, December 13, 2002 3:30 PM Subject: [dom4j-dev] XMLWriter && Attributes with \0 ... :/ > > Hi there, > > *g* before this seems too negative... ;-) Dom4j is GREAT... ;-) > > > > I seem to have a problem with dom4j-1.3; I'm generating an XML > document from within a javacc-Parser. That part works nicely. > > But I noticed, that *sometimes* (rarely, though), some of the > literals, that the parser puts into XML attributes can contain a > 0-byte. > > When dom4j writes this to a file, and later tries to read that > file, I'm getting > > org.dom4j.DocumentException: Error on line 198 of document : An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}". Nested exception: An invalid XML character (Unicode: 0x{2}) was found in the value of attribute "{1}". > at org.dom4j.io.SAXReader.read(SAXReader.java:339) > at org.dom4j.io.SAXReader.read(SAXReader.java:256) > at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:215) > at org.yinyap.frame.JMSReceiver.next(JMSReceiver.java:125) > ... 2 more > > (the only special character in there is a \0 byte right in an > attribute value) > > The xml had been written using a normal dom4j XMLWriter, without any > special options... > > StringWriter sw=new StringWriter(); > XMLWriter writer = new XMLWriter(sw); > writer.write(d); > writer.flush(); > > Shouldn't dom4j escape the \0-bytes? (or did I just forget the > neccessary options to the XMLWriter to make it do so?) > The fact, that dom4j writes xml-Files, that it can't read back > itself, doesn't look all that smart, does it? > > > > > Benedikt > > BEAUTY, n. The power by which a woman charms a lover and terrifies a > husband. > (Ambrose Bierce, The Devil's Dictionary) > > > ------------------------------------------------------- > This sf.net email is sponsored by: > With Great Power, Comes Great Responsibility > Learn to use your power at OSDN's High Performance Computing Channel > http://hpc.devchannel.org/ > _______________________________________________ > dom4j-dev mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/dom4j-dev > __________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com ------------------------------------------------------- This sf.net email is sponsored by: With Great Power, Comes Great Responsibility Learn to use your power at OSDN's High Performance Computing Channel http://hpc.devchannel.org/ _______________________________________________ dom4j-dev mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-dev