You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Be...@helpsystems.com on 2004/08/23 15:24:08 UTC
XMLLayout and CData tag
I'm using an XMLLayout [log4j 1.3.0 alpha] to write events to an XML
file, and I'm getting invalid CData tags in my XML file. What's happening
is that on occasion, a 'binary' character, such as 0x01 is being passed
into the event's message. When the XMLLayout formats the message, it
passes it off to Transform.appendEscapingCDATA, which doesn't replace the
0x01 character with a valid XML character replacement. According to the
"official" XML spec, the valid CData chars are: 0x9, 0xA, 0xD, and just
about anything from 0x20 on up. http://www.w3.org/TR/REC-xml/#NT-Char
The easy answer would be "well, don't put non-text characters in the
message", that doesn't work in my case. I wanted to see if anyone has a
better solution before I spend all of 10 minutes updating my own copy of
the Transform class to "fix" these 'binary' characters.
Thanks!
--Ben
Here's a sample of the invalid XML file, and here's the error when I try
to read it in:
log4j:ERROR Parsing error on line 2 and column -1
log4j:ERROR Illegal XML character: .
org.xml.sax.SAXParseException: Illegal XML character: .
at org.apache.crimson.parser.InputEntity.fatal(InputEntity.java:1100)
at
org.apache.crimson.parser.InputEntity.unparsedContent(InputEntity.java:665)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1979)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at
org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at org.apache.log4j.xml.XMLDecoder.parse(XMLDecoder.java:133)
at org.apache.log4j.xml.XMLDecoder.decodeEvents(XMLDecoder.java:209)