How do I deserialize XML into an object if that objects element root tag is not present?

Viewed 112

I am working with an API that returns all content inside of a <body> XML tag.

I am deserializing my XML into objects using the following function:

    public TObject ParseXML<TObject>(string xml)
    {
        using (TextReader reader = new StreamReader(GetMemoryStream(xml)))
        {
            XmlSerializer serialiser = new XmlSerializer(typeof(TObject));
            return (TObject)serialiser.Deserialize(reader);
        }
    }

How do I deserialize my XML into an object if there is no root tag for that object?

For example, I receive the following response:

<body>
    <active>true</active>
    <allow_quote_requests>false</allow_quote_requests>
    <currency_iso_code>AUD</currency_iso_code>

Everything after the body tag is in fact a Offer object, however because that tag doesn't exist, I am unsure how to deserialize it into that object. It works if I add those properties to the Body model.

1 Answers
Related