c# - De-serializing some XML (via a Stream) into Parent/Child objects -


I have a fairly simple DAL assembly with a SalesEnquiry class in which < List of another vehicle category & lt; T & gt;

We will receive XML files by email which I want to use to populate the examples of my sales class, so I was trying to use de-serialization. I am

I've added the XMLRoot / XMLElement / XMLIgnore attributes for both classes that I think is appropriate. However, when I try to de-serializing, the original sales check is an object population but no child is a vehicle object.

I understand that the de-serialing list & lt; T & gt; may be difficult, but I'm not sure how to avoid problems, or even if I'm struggling.

While debugging, I have successfully sorted a vehicle object on itself, so I am assuming that I am going in the right direction, but when I have a SalesEnquiry XML (which includes one or more child vehicles ), Then the list & lt; Vehicle & gt; is not a population.

Where am I going?

Update :

In a test project, I used to save a SalesEnquiry Loaded a D-serialization into a different SalesEnquiry object. It worked!

So what was the difference? Vehicles were entered as follows:

   & Lt; Vehicle_model & gt; C-Max & lt; / Vehicle_model & gt; ...  

The noticeable thing is that the vehicle has the initial capital, while my incoming XML is not there. In my vehicle category, I've given the class a [XmlRoot ("vehicle")] , though I will make this link, but clearly it is not. It makes sense, I think, because the vehicle is a square in its possession, but it is only an array item within a list inside my sales check.

In that case, the question is - How do I interpret the vehicle class that I come to my list item ( vehicle ) Can XML elements ( & lt; vehicle & gt; ) be mapped? < [XmlArrayItem] (or [XmlElement] for that matter) is not valid on this declaration type.

In this example, I can request that people who use XML & lt; Vehicle & gt; Instead of & lt; Vehicle & gt; , but there may be circumstances where I do not have this freedom, so I want to learn a solution instead of implementing alternative solutions.

Conclusion :

[XmlArrayItem ("vehicle", type (vehicle))] for the current decoration for my list, XML now Absolutely able to de-serialize! Here is a working pair of sections with suitable decoration:

(Note: XmlAnyElement and XmlAnyAttribute are optional, it is a habit that I am promoting the flexibility of the organization.) XMLType ("Inquiry")] [XmlRoot ("Inquiry")] Public Class Check {Private List & amp; Lt; Vehicle & gt; Vehicle = new list & amp; Lt; Vehicle & gt; (); [XMLAllimate ("Inquiry_no")] Public InquiryNumber {Received; Set; } [XmlArray ("vehicle")] [XmlArrayItem ("vehicle", typef (vehicle))] public list & lieutenant; Vehicle & gt; Vehicles {come back} This.vehicles; } Set {this.vehicles = value ?? New list & amp; Lt; Vehicle & gt; (); }} [XmlAnyElement] Public XmlElement [] AnyElements; [XmlAnyAttribute] Public XmlAttribute [] AnyAttributes; } Public class vehicle {{XmlElement ("vehicle_type")] public string vehicle type {get; Set; } [XmlElement ("vehicle_make")] public string vehiclecm {received; Set; } [XmlElement ("vehicle_model")] {Get the public string vehicle model; Set; }}


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -