How to control the de-serialisation of a complex object

Viewed 492

I call a third party web service that returns a HUGE amount of XML Data (around 2mb) and I want to deserialise it into an object in a more controlled way than normal. This is the xml:

<vehicle>
  <vehicleManufacturer>
    <type>1</type>
    <name>A Make</name>
  </vehicleManufacturer>
...

I know I can do the below code to control which elements are serialised to which properties, in this case the Car Make object contains two properties, type and name.

    <System.Xml.Serialization.XmlElement("vehicleManufacturer")> _
    Public Property Make() As CarMake

But what I want to be able to do, if possible, is to deserialise just the name field into the Make property, or even just serialise that whole element and it's contents to text.

    <System.Xml.Serialization.XmlElement("vehicleManufacturer")> _
    Public Property Make() As String

This is a hugely simplified example, so if there are any resources that would help me with this, that would be great.

Another example:

<vehicle>
  <warrantyDetail>
    <warrantyBasicInformation buildStartdate="09/07/2013" warrantyStartDate="31/07/2013"/>
  </warrantyDetail>
</vehicle>

I'd like to get the attributes out of warrantyBasicInformation without having to build the warranty detail and warrantyBasicInformation objects.

Note that this sort of thing would usually be generated from the WSDL, however, I won't be provided with one, I don't have an XSD, and trying to generate one failed. I also know I can implement ISerializable and use an xml reader or linq, but again, that can turn into a lot of code and maybe hard to maintain.

4 Answers
Related