2

I need to read an XML file on a low memory system (don't have access to increase it). I've tried:

$xmlString = file_get_contents($file);
$doc= new DOMDocument();
$doc->loadXML($xmlString);

and

$doc= new DOMDocument();
$doc->load($file);

Both give me memory errors.

Was wondering if there is a way to read the XML sequentially node by node, so only 1 node is in memory at any given time. I don't care how long this takes as it's a nightly batch process.

The structure of the XML is very simple:

        <InventoryItem>
        <SKU>125244</SKU>
        <Quantity>137196</Quantity>
        <Status>Active</Status>
        </InventoryItem>

repeated may times.

Maybe treating it as text?

Much thanks

2 Answers 2

3

You need a pull parser like XMLReader.

Sign up to request clarification or add additional context in comments.

1 Comment

This did the trick, and implementing it took 5 minutes using this example: stackoverflow.com/questions/1835177/how-to-use-xmlreader-in-php Muchas Gracias!
0

You want to use SAX parsing (using the PHP functions, or XMLReader, as mentioned in another answer).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.