follow loading progress of huge XML files

后端 未结 3 820
一个人的身影
一个人的身影 2021-01-18 05:10

I try to follow the loading progress of big XML files (I\'m not the provider of these files) in dotnet (C#, framework 3.5 SP1) : from 1 MB to 300 MB over a network file shar

3条回答
  •  鱼传尺愫
    2021-01-18 06:11

    How about using DataSet.Read()?

    or,

    // Create the document.
            XmlDocument doc = new XmlDocument();
            doc.Load(file);
    
            // Loop through all the nodes, and create the list of Product objects .
            List products = new List();
    
            foreach (XmlElement element in doc.DocumentElement.ChildNodes)
            {
                Product newProduct = new Product();
                newProduct.ID = Int32.Parse(element.GetAttribute("ID"));
                newProduct.Name = element.GetAttribute("Name");
    
                // If there were more than one child node, you would probably use
                // another For Each loop here and move through the
                // Element.ChildNodes collection.
                newProduct.Price = Decimal.Parse(element.ChildNodes[0].InnerText);
    
                products.Add(newProduct);
            }
    

提交回复
热议问题