I have a XML Like Below, But i am not able to parse it. Please help me to parse the below XML.
<?xml version="1.0" encoding="utf-8"?><soap:Envelope
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body>
<GetResponse xmlns="http://tempuri.org/"><GetResult>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<a>hi1</a>
<b>hi2</b>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<a>hi3</a>
<b>hi4</b>
</Table>
</NewDataSet>
</diffgr:diffgram>
</GetResponse></GetResult>
</soap:Body>
</soap:Envelope>
Here i want the results of the Table (i.e a,b ) tag. I tried using Linq but i am not able parse it. i tried the code some thing like this:
//XML will be there in response string
String response = e.response;
public static String myNamespace = "http://tempuri.org/";
XDocument reader = XDocument.Parse(response);
var results = from result in reader.Descendants(XName.Get("GetResponse", myNamespace))
select result.Element("GetResult").
But this code is returning null.
EDIT: I used below code: String response = e.response;
public static String myNamespace = "http://tempuri.org/";
XDocument reader = XDocument.Parse(response);
XElement resultElement = reader.Descendants(XName.Get("GetResult", myNamespace)).Single();
XElement resultElement1 = resultElement.Descendants(XName.Get("NewDataSet", "")).Single();
So now resultElement1 i got XML Like Below:
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<a>hi1</a>
<b>hi2</b>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<a>hi3</a>
<b>hi4</b>
</Table>
</NewDataSet>
So Now how can i find the values of tag and tag ?
Thanks in advance.
The element
GetResult
is also in thehttp://tempuri.org
namespace, so that is why you select clause is not finding anything.Anyhow, I would simplify the query to the following:
What is blocking you?
You can try this: