Handling funny characters in XML with XML::Simple XMLin()
"Mark Knoop" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.xml |
|---|---|
| Message-ID | <[email protected]> |
Hi I use XML::Simple to read in XML style logs which then get processed. This code standardises the procesing of XML logs from many different places. Infrequently XML logs which are written by a 3rd party application (ie I cannot do anything about the logs at source) contain a non ascii character which breaks XMLin(). I have put this inside an eval so it does not kill the application however I would really like to ignore this character so I can process the rest of the information in the log as normal. I could preprocess all the log files and strip out the offending character but this seems a bit longwinded. Is there a way I can just get XMLin to ignore or handle the character so I don;t have to jump through too many hoops to avoid losing the odd set of data when this character is present? I looked at NumericEscape but it seems this only works for writing out hashes to XML which contain funny characters and cannot be used for handling funny characters on the way in. An example of the data is: <?xml version="1.0" encoding="UTF-8"?> <CDR-ROOT><DATA> <CDR SessionID="200810051223202224961753020" SessionStartTime="20081005112344+01" SessionEndTime="20081005112445+01" SessionDuration="61" SessionStartSystemTime="1223202224" SessionEndSystemTime="1223202285" UserAgent="@" /> </DATA></CDR-ROOT> Where the UserAgent attribute contains the offending character. The error I get is not well-formed (invalid token) at line 3, column 219, byte 277 at C:/Perl/lib/XML/Parser.pm line 187 I'm hoping there is a trick I am missing... Cheers Mark _______________________________________________ Perl-XML mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs