split xml document into chunks

后端 未结 3 569
慢半拍i
慢半拍i 2021-01-07 03:26

I have a large xml document that needs to be processed 100 records at a time

It is being done within a Windows Service written in c#.

The structure is as fo

3条回答
  •  一向
    一向 (楼主)
    2021-01-07 03:55

    If the reason to process 100 orders at a time is for performance purposes, e.g. taking too much time and resource to open a big file, You can utilize XmlReader to process order element one at a time without degrading the performance.

    XmlReader reader = XmlReader.Create(@"c:\foo\Doket.xml")
    while( reader.Read())
    {
      if(reader.LocalName == "order")
      {
         // read each child element and its value from the reader.
         // or you can deserialize the order element by using a XmlSerializer and Order class
      }     
    }
    

提交回复
热议问题