Oddible
Oddible

Reputation: 121

How to modify elements in a very large XML file in PHP (or C#)

I receive very large xml files which need spot edits (adding elements at particular nodes). The file size makes using DOMDocument or SimpleXML not an option. I'm using XMLReader to parse the file but it appears that my only option is to completely rewrite the file using XMLWriter. I'm curious if there is a better way? Perhaps something that lets me edit the file at the cursor location of XMLReader?

Ideally I'd be doing this on the fly with PHP but I make it work doing a one off with C# to get things up and running if there is a tool that makes this work more efficiently.

Upvotes: 0

Views: 421

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476813

If the edits can be expressed using XSLT, I would recommend this since XSLT parsers optimize the query and in most cases perform a single run on the file...

XSLT is a language (in XML) to describe how to rewrite an XML document into another one. Most XSLT parsers are highly optimized (in time, memory and disk usage).

Upvotes: 1

Related Questions