Efficient Parsing of XML

后端 未结 1 1748
清歌不尽
清歌不尽 2020-12-22 11:06

Good day,

I\'m writing a program in C# .Net to manage products of my store,

Following a given link I can retrieve an XML file that contains all the possible

相关标签:
1条回答
  • 2020-12-22 11:41

    With large XML files you have to use an XmlReader. The code below will read one Product at a time.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                XmlReader reader = XmlReader.Create("filename");
                while(!reader.EOF)
                {
                    if (reader.Name != "Product")
                    {
                        reader.ReadToFollowing("Product");
                    }
                    if (!reader.EOF)
                    {
                        XElement product = (XElement)XElement.ReadFrom(reader);
                        string lastUpdated = (string)product.Element("lastUpdated");
                    }
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题