I'm trying to pass on data wrapped in xml from a serial device and that data must retain all of it's original characters.
My understanding of CDATA is that it could contain illegal characters as it's not parsed by the xml parser, but when using the XCData class in asp.net it throws an illegal character exception. Here is the code.
return new XElement("ac",
new XAttribute("name", name),
new XAttribute("id", id),
new XElement("interface_id", interface_id),
new XElement("event_type", event_type),
new XElement("interface_type", interface_type),
new XElement("data", new XCData(data))
).ToString();
If I remove the line adding the XCData, the code runs fine, so I know the illegal character is in the data variable.
Here is the exception I am getting
An unhandled exception of type 'System.ArgumentException' occurred in System.Xml.dll
Additional information: '.', hexadecimal value 0x00, is an invalid character.
So I guess the question is, am I wrong about CDATA, if so, is it even possible to maintain data integrity through xml?
XML cannot contain the null character anywhere, not even in CDATA.
Use a binary-to-plaintext encoding for raw binary data, preferably base64.
Using base64 makes using CDATA superfluous.