Any problems to loop XML with 15K lines?

Post Reply
automation
Member
Posts: 40
Joined: Tue Jan 15, 2019 10:19 pm

Any problems to loop XML with 15K lines?

Post by automation » Thu Apr 29, 2021 9:24 pm

I have two XML:s, XML 1 with 200 lines and XML 2 with 15.000 lines. I need to compare every specifik node in XML 1 with every specifik node in XML 2.

I do this with in nested foreach loop in PowerShell today and it takes less than a second. How can Swithscripter handle this?

Something like this

Code: Select all

foreach (Record1 in XML1)
{

foreach (Record2 in XML2)
{
//compare values
}

}

freddyp
Advanced member
Posts: 609
Joined: Thu Feb 09, 2012 3:53 pm

Re: Any problems to loop XML with 15K lines?

Post by freddyp » Fri Apr 30, 2021 8:50 am

There is a plethora of npm packages for processing XML files using NodeJS. I see no problem whatsoever.

There are two possible approaches. Either you read the XML into a JS object with a package like xmltojson, or you use a package that processes the XML natively.

I find the first approach useful for simple XML files that mainly use Text nodes and no attributes and no namespaces. Otherwise the JS object structure becomes quite complex and difficult to read. That is me! Others will disagree. And a large file is not necessarily complex, so this may be a good fit. When it is a good fit, this is the easier of the two.

For the second approach I use the packages xmldom and xpath. You need both: xmldom for reading the XML and I forgot what xpath does.

On a side note, I wonder if it is really necessary to loop over XML 2. Is it not possible to loop over XML 1 and do an xpath search on XML 2 with whatever information you have from XML 1? In which case, of course, the second method is the better one.

Post Reply