I have the following XML as string and need to convert it to JSON:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<Results>
<Summary>
<Status xsi:type="xsd:boolean">true</Status>
<etc xsi:type="xsd:string">etc</etc>
</Summary>
</Results>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
My expected output is:
{
"Summary": {
"Status": true,
"etc": "etc"
}
}
My attempt
I am using the following code
var doc = new XmlDocument();
doc.LoadXml(xmlString);
var json = JsonConvert.SerializeXmlNode(doc);
var jObject = JObject.Parse(json);
var final = Convert.ToString(jObject["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["Results"]["Summary"]);
However, this results in a weird JSON like the following:
{
"Status": {
"@xsi:type": "xsd:boolean",
"#text": "true"
},
"etc": {
"@xsi:type": "xsd:string",
"#text": "etc"
},
}
What should I do?