I'm developing a C# library with .NET Framework 4.6.2 that parse big xml files.
This library will be part of a Windows Service and I want to don't waste memory loading XML files at once using XDocument.
Maybe there is a better option, but I've decided to use XmlReader instead. In particular, the method ReadToFollowing.
I read that XmlReader represents a reader that provides fast, noncached, forward-only access to XML data.
The xml file I want to read has one section with some data that I have to check before continue reading. Another section with more useful data, and a very big last section with tons of codes.
If the file always has the same section order is Ok, but I'm not sure, and this is my question, if the file will always have the same section order that I has described above.
Will a XML file have the same section order? I have its XSDs files and I don't know if these files describe the order in its sections.
An example of XML file is this (I couldn't share the original one due to NDA):
<?xml version="1.0" encoding="UTF-8"?>
<Incomming_Msg xmlns="http://xxx/xxx.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xxx/xxx.2-messages.xsd ">
<DataToCheck>
<Field1>
<SubField1>123456789</SubField1>
</Field1>
<Field2>
<SubField2>123asz11-12asd</SubField2>
<!-- Omitted for brevety -->
</Field2>
<!-- Omitted for brevety -->
</DataToCheck>
<DataToInsert1>
<!-- Omitted for brevety -->
</DataToInsert1>
<DataToInsert2>
<!-- Omitted for brevety -->
</DataToInsert2>
<DataToInsert3>
<!-- Omitted for brevety -->
</DataToInsert3>
<TonsOfCodes>
<CodeLevel>
<Code>
<Serial>1234567890</Serial>
</Code>
</CodeLevel>
<!-- Omitted for brevety -->
<!-- This section could be very very big -->
</TonsOfCodes>
</Incomming_Msg>
For example, if the xml file comes with TonsOfCodes
section at the beginning of the file, reading the file to find the section DataToCheck
will be very slow.