I am trying to figure out how to remove an element (and its children) from an XML file which is very large in php (latest version).
I know that I can use dom and simpleXml, but this will require the document to be loaded into memory.
I look at the XML functions writer / reader / parser and googling, but nothing seems to be happening on this issue (all answers recommend using dom or simpleXml). It can't be right - am I missing something?
The closest I found is (C #):
You can use XmlReader to read your xml sequentially (ReadOuterXml may be useful in your case to read the entire node at a time). Then use XmlWriter to write all the nodes that you want to save. ( Removing nodes from large XML files )
Really? Is this an approach? Do I need to copy the entire huge file?
Is there no other way?
Confirm
As suggested,
I could read the data using a php XML reader or parser, possibly its buffer, and also write / dump + add it back to the new file.
But is this approach practical?
I have experience splitting huge XML files into smaller parts, mainly using the proposed method, and it took a very long time to complete the process.
My dataset is currently not large enough to give me an idea of ββhow this will work. I could only assume that the results would be the same (very slow process).
Does anyone have experience putting this into practice?
user1267259
source share