I have some third party xml, that I'm trying to parse.
The question is similar to this one in that I'm looking to get at pseudo xml code buried inside one of the elements. However, the result I need is different.
Here's the xml that's returned:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PostApplication_V6Response xmlns="http://xxxService.org/">
<PostApplication_V6Result>string</PostApplication_V6Result>
</PostApplication_V6Response>
</soap:Body>
</soap:Envelope>
I'm using Linq to XML - I can return the element <PostApplication_V6Result>
- this is the lowesst element in the tree I can retrieve.
Using this code:
var name = "{http://xxxService.org/}PostApplication_V6Result";
var soap = XDocument.Parse(result)
.Descendants(name)
.First();
However, the value contained within that element is some kind of pseudo xml - not xml but xml lookalike.
Here's what's contained inside:
<xxxService>
<Application>
<Status>Accepted</Status>
<RedirectUrl>http://www.google.com?abc=123</RedirectUrl>
<Value>100</Value>
</Application>
</xxxService>
I've tried just about everything to get the data out, but I get either an invalid char '=' error or a data at root invalid message.
Ideally I want to get the data including within the "Application" node into a state where I can run it through a generic parser like the one below, but if I have to do something manually I will. I've been trying to solve this for a couple of days now.
public static T Deserialise<T>(this XElement element)
{
var serializer = new XmlSerializer(typeof(T));
using (var reader = element.CreateReader())
{
return (T)serializer.Deserialize(reader);
}
}
Any help appreciated.
UPDATE
Here's the full xml thats returned- as you can see the inner portion is in fact html not xml.
<soap:body><postapplication_v6response xmlns="http://xxxService.org/"><postapplication_v6result><xxxService>
<Application>
<Status>PURCHASED</Status>
<RedirectURL>http://www.google.com?test=abc&xyz=123</RedirectURL>
</Application>
</xxxService>
</postapplication_v6result></postapplication_v6response></soap:body></soap:envelope>