0

What is the best way to compare elements of two large XML files with products?

For example: If one XML file contains a product with the same id as in a second XML file, I'd like to select the product which has newer date_added and save it to new file.

Sample of my XML code:

<products>
    <product id="1" date_added="2016-05-05">
        <category><![CDATA[Category1]]></category>
        <name><![CDATA[Product name]]></name>
        <description><![CDATA[Description...]]></description>
        <attributes>
            <a name="Producent"><![CDATA[Producent]]></a>
            <a name="PN"><![CDATA[12345]]></a>
        </attributes>
    </product>
</products>
Tom Lord
  • 27,404
  • 4
  • 50
  • 77

1 Answers1

0

For large XML files I would say that your best shot is to use the SAX XML Parser.

It is a little complicated to manage if you compare it to SimpleXML, DOM parser or XMLReader but in terms of memory management I would say is what you are looking for.

Then, for your queries I would go for XPath and you can find nice clues here: Is there any XPath processor for SAX model?

Community
  • 1
  • 1
Raul Leaño Martinet
  • 2,035
  • 6
  • 28
  • 44