I have the following XML:
<iq xmlns="jabber:client" to="39850777771287777738178727@guest.google.com/agsXMPP" xml:lang="en" id="sub23" from="search.google.com" type="result">
<pubsub xmlns="http://jabber.org/protocol/pubsub">
<subscription subscription="subscribed" subid="5077774B57777BD77770" node="search" jid="39850777771287777738178727@guest.google.com/agsXMPP" />
</pubsub>
</iq>
I tried parsing from linq to sql, but it doesn't seem to understand that these are different nodes. It groups all iq into one element.
Can someone help with parsing this using XML?
The data I want to get is subid = "5077774B57777BD77770" and id = "sub23"
Thank!
Edit:
Here the code that I have tried to do this in two ways:
XDocument doc = XDocument.Parse("<xml>" + iq.ToString() + "</xml>");
var results = from feed in doc.Elements("xml")
select new
{
Id = (string)feed.Element("iq").Attribute("id"),
Subid = (string)feed.Element("iq").Element("pubsub").Element("subscription").Attribute("subid")
};
and
var doc = new System.Xml.XmlDocument();
doc.LoadXml(iq.ToString());
var searchId = doc.Attributes["id"];
var subid = doc.SelectSingleNode("/pubsub/subscription").Attributes["subid"];
source
share