tags:

views:

27

answers:

2

How to adjust this code to work when RESPONSE is no more string but Ling.Xelement?

        String response = "anyxml data";

        XmlDocument xmlDocument = LoadXMLDocument(response);

        XmlNodeList nodeList = xmlDocument.GetElementsByTagName("fql_query_response");

        if (nodeList != null && nodeList.Count > 0)
        {
            if (nodeList[0].HasChildNodes)
            {
                XmlNodeList results = xmlDocument.GetElementsByTagName("event_member");
                Dictionary<string, EventUser> eventUserDict = new Dictionary<string, EventUser>();
                foreach (XmlNode node in results)
                {

                    myuids.Add(Int64.Parse(node.FirstChild.InnerText));

                }


            }
A: 

You can use XElement.ToString() to create an XML string from the XElement which you can load into your XmlDocument:

XmlDocument xmlDocument = LoadXMLDocument(yourXElement.ToString());
Prutswonder
A: 

Do you mean you want to create an XmlDocument from an XElement?

The simplest way to do that may well be this:

XmlDocument doc = new XmlDocument();
using (XmlReader reader = element.CreateReader())
{
    doc.Load(reader);
}

However, I have to say the code would probably be simpler if you just converted it all to LINQ to XML, which is generally a nicer API to start with. Is there any reason why you want to stay with XmlDocument?

Jon Skeet