Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how can i store a xml nodelist in dataset or arraylist..

please help me in this Quick.

thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 12-Sep-11 2:29am    
Why? Why using ArrayList at all -- it's superseded by System.Collections.Generic.List?
--SA

1 solution

System.XML namespace of .NET framework, play a major role for your problem. Herez the sample code:

XML
static void Main(string[] args)
{
    XmlDocument xmldoc = new XmlDocument();
    xmldoc.LoadXml("<root><node /><node /><node /></root>");
    XmlNodeList xmlNodeList = xmldoc.SelectNodes("//node");
    XmlNode[] array = (
        new System.Collections.Generic.List<XmlNode>(
            Migrate<XmlNode>(xmlNodeList))).ToArray();
}

public static IEnumerable<T> Migrate<T>(System.Collections.IEnumerable enumerable)
{
    foreach (object current in enumerable)
    {
        yield return (T)current;
    }
}
 
Share this answer
 
Comments
Member 14369124 22-May-19 20:48pm    
I would like to thank you for this way of converting xmlnodelist to arraylist but I've experienced problem with it. If you're getting a recurring node in an xml, it only gets the values of the Childnodes of the CH block, then throws it away after the loop.
The last data would be the last CH Block it could find.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900