I am working on a project where i have an online solution, where you can upload an xml file and parses the data within the xml to the database. The files can now be up to 1GB big and my solution must be able to handle this which gives me some difficulty for obvious reasons. My idea was to send the data to the database in chunks.
Here is a small example of how the xml file can look
<BPM6 language="english" submissionType="normal" version="14">
<masterdata tlf="" by="" postnr="" gadenavn="" firmanavn="" loebenr=""
refperio="201711" idno="61092919">
<kontaktpersoner>
<person fuldtnavn="Morten Nystrup Rasmussen" tlf=""
email="mnr@nationalbanken.dk" />
</kontaktpersoner>
</masterdata>
<AK1>
<AK1MedIsin>
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J"/>
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J"VaerdiPrincip="M"Fritekst="
" />
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J" VaerdiPrincip="M" Fritekst="
" />
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J" VaerdiPrincip="M" Fritekst="
" />
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J" VaerdiPrincip="M" Fritekst="
" />
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J" />
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J"VaerdiPrincip="M"/>
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J"VaerdiPrincip="M"/>
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J"VaerdiPrincip="M"/>
<data Isin="123" Koncern="D" Valuta="ANG" VPreg="J" VaerdiPrincip="M" />
</AK1MedIsin>
</AK1>
<OB2a>
<OB2aUdenIsin>
<data InternKode="3" Branche="BZ2" Sektor="1120"/>
<data InternKode="4" Branche="BZ2" Sektor="1120"/>
<data InternKode="5" Branche="BZ2" Sektor="1120"/>
<data InternKode="6" Branche="BZ2" Sektor="1120"/>
<data InternKode="7" Branche="BZ2" Sektor="1120"/>
</OB2aUdenIsin>
</OB2a>
</BPM6>
The full xml files are obviously a lot bigger. My main problem is that i have to read the data within the nodes "AK1MedIsin" and "OB2aUdenIsin" and these names are unknown and will change from file to file.
using (var reader = XmlTextReader.Create(File.OpenRead(@"C:\data.xml")))
{
var state = State.PreMasterData;
if (reader.MoveToContent() == XmlNodeType.Element)
{
while (reader.Read())
{
switch (state)
{
case State.PreMasterData:
if (reader.Name == "masterdata")
{
var masterDatastring = ReadMasterData(reader);
state = State.PostMasterData;
break;
}
break;
case State.PostMasterData:
//Read chunks of the data of the child notes of BPM6
break;
}
}
}
}
Reading the MasterData is not a problem because that name is always the same. So i can just use xpath or reader.name to go to the note and read the lines one by one. But how to do this when i dont know the name of the node has been difficult for me. I tried to use the method reader.ReadSubtree(), but that seems not possible.