Merge entries in XMLfile (SimpleXML in PHP)
Posted
by Cudos
on Stack Overflow
See other posts from Stack Overflow
or by Cudos
Published on 2010-05-14T13:09:55Z
Indexed on
2010/05/14
13:14 UTC
Read the original article
Hit count: 257
Hello.
I have this in my XML file:
<product name="iphone">
<variant name="iphone" product_number="12345" price="500" picture="iphone.jpg">
<description><![CDATA[iphone]]></description>
<short_description><![CDATA[]]></short_description>
<deliverytime><![CDATA[]]></deliverytime>
<options>
<option group="Color" option="Black" />
</options>
</variant>
</product>
<product name="iphone">
<variant name="iphone" product_number="12345" price="500" picture="iphone.jpg">
<description><![CDATA[iphone]]></description>
<short_description><![CDATA[]]></short_description>
<deliverytime><![CDATA[]]></deliverytime>
<options>
<option group="Color" option="White" />
</options>
</variant>
</product>
I want to merge it into this (Note that I merge the options tag):
<product name="iphone">
<variant name="iphone" product_number="12345" price="500" picture="iphone.jpg">
<description><![CDATA[iphone]]></description>
<short_description><![CDATA[]]></short_description>
<deliverytime><![CDATA[]]></deliverytime>
<options>
<option group="Color" option="Black" />
<option group="Color" option="White" />
</options>
</variant>
</product>
Preferably I want to do it all in the memory since I will process it further afterwards.
© Stack Overflow or respective owner