2011-04-06, 04:45:48
(This post was last modified: 2011-04-06, 04:47:46 by infos.media.)
I'm currently learning how to use SimpleXML and would like a hint on how to save modifications back to a XML file? Let's take this example with (still) hard-coded element content:
I read up on asXML(), but I don't get it. In example 1 given at php.net, the output includes <?xml version="1.0"?> which is not what I want. Example 2 doesn't have it, but uses XPath. Is example 2 possibly what I want?
Code:
# Load the feed file
$xml = simplexml_load_file($thp_newsfeed_atom_template_destination);
# Add an entry element as child
$entry = $xml->addChild('entry');
# Add child elements to entry
$entry->addChild('title', 'Page XYZ has been created');
$entry->addChild('link', 'http://');
$entry->addChild('id', 'Generate UUID or other id');
$entry->addChild('updated', 'Insert update time');
$entry->addChild('summary', 'Repeat title?');
I read up on asXML(), but I don't get it. In example 1 given at php.net, the output includes <?xml version="1.0"?> which is not what I want. Example 2 doesn't have it, but uses XPath. Is example 2 possibly what I want?