How can I modify an xml file in php?
. Html/article/hardware/008.html
Http://www.niutuku.com // </list>
Http://www.niutuku.com // </list>
Http://www.niutuku.com // </list>
3
The above is the xml file I want to modify. Four in And smallinfo attributes, please help me.
Reply to discussion (solution)
This mainly involves xml DOM operations. let's take a look at this content.
Use xml DOM
if ( file_exists ( 'out.xml' )) { $xml = simplexml_load_file ( 'out.xml' ); foreach ($xml->pic->list as $key => $value) { $attr = (array) $value->attributes (); var_dump($attr['@attributes']['smallinfo']); } } else { exit( 'Failed to open test.xml.' );}
We recommend that you use simple_html_dom or phpQuery to change the value.
$ S = <XML
. Html/article/hardware/008.html
Http://www.niutuku.com // </list>
Http://www.niutuku.com // </list>
Http://www.niutuku.com // </list>
3
XML; $ xml = simplexml_load_string ($ s); for ($ I = 0; $ I
Pic-> list); $ I ++) {$ xml-> pic-> list [$ I] = $ I; $ t = $ xml-> pic-> list [$ I]-> attributes (); $ t ['smallpath'] = $ I ;} echo $ xml-> asXML ();
0
1
2
3
3