I have a numb开发者_运维问答er of XSD files that define the schema for some XML. I generated classes using the XSD.EXE tool and added this to my project.
The schema itself has a number of nested types that deserialize nicely, until I get to a segment defined like this:
<xs:element name="SamplePayload" type="xs:anyType"/>
This leaves me with the raw System.Xml.XmlNode. I know the specific type/class this section should be deserialized as (it is specified in the XML itself and isn't static - it can be any of a few different types). I was hoping that I could just call Deserialize in the XmlSerializer class, passing in this segment, but of course it's not really valid XML on its own.
Is there an easy way I can load this segment into my classes without having to manually parse this stuff myself (this segment represents another fairly complex set of XML so that would be really painful).
I have no control over the XSD files so I can't just change them.
The easiest way that I can think of is to write a preprocessor stage that simply replaces all instances of the string xs:anyType
with your desired type.
You could also modify the generated classes to do the conversion on the fly.
精彩评论