xmlwriter - Rewrite existing attribute value from Xml String? -
is possible rewrite existing attribute xml string?
if have:
$xml_str = "<root> <nodea attr1="value1"></nodea> </root>"; //rewrite $xml_str
how can find nodea
, @ same time rewrite value1?
// save xml string physical path file_put_contents($xml_save_path.ds.$xml_filename, $xml_str);
you can use simplexml parse xml in php.
here's simplified version value1
, replace value2
echo new xml.
$xml_str = "<root> <nodea attr1='value1'></nodea> </root>"; $doc = simplexml_load_string($xml_str); $doc->nodea['attr1'] = 'value2'; echo $doc->asxml();
Comments
Post a Comment