xmlns namespace resilency

night_spy

New Member
I receive data from a server as utf-8 encoded xml messages that look like\[code\]<?xml version="1.0" encoding="utf-8"?><Data namespace="http://example.com/data">...</Data>\[/code\]The noteworthy thing about the example is that the "namespace" qualifier should in reality be the "xmlns" qualifier specifying the default xml namespace. The code for serialization / deserialization was (auto-) generated from a schema definition file, and both the xsd as well as the documentation that came along with it pretty much confirm that this is a bug. However, this also means that the Data object now lives in the global / empty namespace (xmlns="") and the autogenerated code fails with the typical \[code\]"There is an error in XML document ..."\[/code\] and \[code\]"<Data xmlns=''> was not expected."\[/code\] kind of exception that the XmlSerialzier throws during deserialization that people see when the namespaces of the deserialization attributes / code and the xml document do not match.While it is fairly easy to modify the autogenerated code and "hotfix" the \[code\]Namespace\[/code\] definitions to e.g.\[code\][System.SerializableAttribute()][System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="")][System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]public partial class Data {\[/code\]what I really wish is namespace resilency - that is, if at some point in the future the issue is fixed by the guys that provide me the data, I do not wish to be forced to adapt the \[code\]Namespace\[/code\] definitions in the code again (any xmlns change will break the deserialization code with the aforementioned exception).That is, I want code that is able to handle both the faulty xml above as well as e.g.\[code\]<?xml version="1.0" encoding="utf-8"?><Data xmlns="http://example.com/data">...</Data>\[/code\]or even (e.g. if they decide to go "backwards compatible")\[code\]<?xml version="1.0" encoding="utf-8"?><Data xmlns="http://example.com/data" namespace="http://example.com/data">...</Data>\[/code\]What options do I have?
 
Back
Top