1

I have this snippet of XML and I'm attempting to Deserialize it. I have tried the following class to deserialize to but I dont get the address lines I only get the city state and postal code. Can someone point out my mistake? I can't see what I'm doing wrong. XML and class are just below.

XML:

         <RemitTo>
            <Address>
                <AddressLine lineNumber="1">Blah blah</AddressLine>
                <AddressLine lineNumber="2">bah bah bah</AddressLine>
                <AddressLine lineNumber="3">bah3</AddressLine>
                <City>Minneapolis</City>
                <State>MN</State>
                <PostalCode>55413</PostalCode>
                <Country isoCountryCode="US">United States</Country>
            </Address>
        </RemitTo>

CLASS:

[XmlRoot("RemitTo")]
    public partial class RemitTo
    {
        [XmlElementAttribute("Address")]
        public List<Address> RemitToAddress { get; set; }

    }

    public partial class Address
    {


        [XmlArray("Address")]
        [XmlArrayItem("AddressLine")]
        public List<string> AddressLine { get; set; }


        public string City { get; set; }
        public string State { get; set; }
        public string PostalCode { get; set; }
        public string Country { get; set; }
    }

In code im doing this.

RemitTo i;
XmlSerializer serializer = new XmlSerializer(typeof(RemitTo));
i = (RemitTo)serializer.Deserialize(addressReader);

1 Answer 1

3

It should be as simple as this

    [XmlElement("AddressLine")]
    public List<string> AddressLine { get; set; }

XmlArray isn't applicable, since we are already inside the Address class, and there is no further wrapper element around the child items.

Reference

Sign up to request clarification or add additional context in comments.

2 Comments

StuartLC I must have spent 4 hours trying to figuered this out. Thank you for taking the time!. God i feel like such a dumb A**.
More than welcome - I've spent many frustrating hours myself trying to shape xml into entities. When I get really stuck, I tend to use XSL to pre-project the xml into something closer to my entity graph.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.