[.net] null character in xml file

Started by
4 comments, last by apatriarca 16 years, 10 months ago
Hi, I have to parse an xml file generated by a program. That program have a bug and insert a null character (0x00) in the file. How can I parse that file using C#? The rest of the file is a valid xml file, so I only need a way to ignore that character.
Advertisement
Could you not run the file through a post processor that strips out null characters, then you would have a valid XML file to work with.
Hi, I can pre-process the file but I would like to know if there is a way to do it without pre-processing.
Simple answer, no. An xml file with a null character in it is not a valid xml file, so you can't parse it. You need to write characters like null as a standard html escape code.

Therefore you can
- Run a program after the buggy xml writer that reads in the xml and removes the null's (ie. rip-off's post-process idea)
- Read the xml into a stream, replace the null's, then parse the stream using the xmlreader (pre-process)
- Write your own custom xml parser
Quote:Original post by Headkazeescape code

Exactly why I'll never use XML again unless there is absolutely no alternative. Like when providing RSS feeds. XML has too many restrictions on what kind of characters may occur a file.

Programming since 1995.
Quote:Original post by T1Oracle
Quote:Original post by Headkazeescape code

Exactly why I'll never use XML again unless there is absolutely no alternative. Like when providing RSS feeds. XML has too many restrictions on what kind of characters may occur a file.

I doesn't like xml but I have no choice. I have solved the problem reading the file in a stream before parsing it and removing the null character when I find it.

This topic is closed to new replies.

Advertisement