Skip to content
Advertisement

Split big XML file using php

Im trying to group a big file into each individual file (group on their position index )

Sample XML:

JavaScript

Expected output: firstposition.xml

JavaScript

secondposition.xml

JavaScript

thirdposition.xml

JavaScript

Where am I on this situation? I can split the file and manipulate them as needed but I wasn’t able to achieve my desired result.

First Im getting all positions and contract like this

JavaScript

then I iterate into each position ( just getting the position name value and pushing it into another array)

JavaScript

then iterate again into the $positions now comparing them and remove unnecessary tags as needed

JavaScript

This works fine I was able to remove non-first position the problem I have is on removing the contract based on the position name. If I remove it via $c_cont = $contracts ->item($i) this obviously remove random contract (depends on iteration ) my goal is to look up on the contract based on the position name and remove those.

Now, really my final question is. How can I look up inside $contracts with criteria?

the idea I have in mind is

JavaScript

this visualization using SQL terms but not sure how can I achieve that on PHP.

If I got it I can just delete it like the way above $c_cont->parentNode->removeChild($c_cont);

Sorry for the long post and thanks in advance for the help.

Advertisement

Answer

In the end I just compare the values with 2 loops, not sure if this is the most efficient but well it solved my problem.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement