How to modify a xml file using PHP? use a node to retrieve the value of new child nodes and add them
Posted
by Avinash Sonee
on Stack Overflow
See other posts from Stack Overflow
or by Avinash Sonee
Published on 2010-06-16T06:43:51Z
Indexed on
2010/06/16
7:12 UTC
Read the original article
Hit count: 275
I have pasted the example of what I need here : http://pastie.org/1005178
I have a xml file with say the following info
<state>
<info>
<name>hello</name>
<zip>51678</zip>
</info>
<info>
<name>world</name>
<zip>54678</zip>
</info>
</state>
Now I need to create a new xml file which has the following
<state>
<info>
<name>hello</name>
<zip>51678</zip>
<lat>17.89</lat>
<lon>78.90</lon>
</info>
<info>
<name>world</name>
<zip>54678</zip>
<lat>16.89</lat>
<lon>83.45</lon>
</info>
</state>
So, basically I need to add lat and lon nodes to each info element. these lat and lon correspond to the zip code which are stored in a mysql file which contains 3 fields - pin, lat and lon
How do i do this recursively. I have say 1000 info elements in a file
Please give me a sample code because I have already tried using simplexml and read the documentation but doesn't see to understand it properly
© Stack Overflow or respective owner