XElement and hexadecimal value 0x0C is an invalid character
I’ve a little library that build excel files in openXml format. It is based on LINQ to XML, and permits you to open an excel file with open xml sdk, then manipulate the content and showing it to the user.
Today for a particular set of data I got
hexadecimal value 0x0C, is an invalid character
This is a standard error of Xml, due to the fact that there are some character in ASCII set that cannot be included in XML content. Since I read data from a db, it happens that some strings contain char 0x0C ( \f ). To accomplish this with the minimum effort I simply write such a class
|
|
This is a simple wrapper for an XmlWriter, since I got this error when I try to write to a XmlWriter an XElement that contains those non valid chars. All functions are simple wrappers of base class except that one that write a string.
|
|
The first test verify if All characters in input string are valid chars, if yes I can simply use base function, while if there is a single invalid chars, I need to copy all chars into a temp string builder, discarding invalid chars. Now I can use whenever I write XElement to a XmlWriter
|
|
Et voilà , now everything works ok again.
Alk.
Tags: Xml