Use XmlNode.OuterXml
property:
string QueryBuf = QueryElem.OuterXml;
returns
<query xmlns="jabber:iq:roster"><item jid="al@abc.def.com" name="Albert" subscription="both"><group>A</group></item></query>
Question
I am trying to obtain the complete string of the query element (2nd element) within an xml string like the following:
"<iq type=\"result\" id=\"Roster\" to=\"JJJ@mail.kkk.com\"><query
xmlns=\"jabber:iq:roster\"><item jid=\"al@abc.def.com\" name=\"Albert\"
subscription=\"both\"><group>A</group></item></query></iq>"
I am using XmlDocument and code that looks like this:
XmlDocument XDoc = new XmlDocument();
XDoc.LoadXml(DataBuf);
XmlElement QueryElem = XDoc.DocumentElement["query"];
string QueryBuf = QueryElem.InnerXml;
I need the full xml string starting with the query element. The InnerXML method only returns the data starting with the "item" data.
How can I obtain the full string starting with query that ends with /query and that does not contain the iq element data?
Solution
Use XmlNode.OuterXml
property:
string QueryBuf = QueryElem.OuterXml;
returns
<query xmlns="jabber:iq:roster"><item jid="al@abc.def.com" name="Albert" subscription="both"><group>A</group></item></query>