Hiya am a newbie so be gentle please.
I am trying to discover how to update a blooming attribute on an existing xml file????? and its driving me mental.
I have loaded the wee besom into php.
Am using simplexml.
I can read the xml and display the atrribute
. . . I can write a new xml file with the attribute
BUT what I would so dearly love to do is read the xml file and then change the attrib . . . . .and then update the XML.
Is this possible I am beginning to ask myself.
Now normaly I would store the data in mysql but am using flash which is using the xml for data so would like to adjust the xml content.
Heres a wee snippet of the XML
<calendar>
<once>
<date year="2009" month="5" day="13">
<event>I went wobbly</event>
</date>
<date year="2009" month="5" day="14">
<event>I started to cry</event>
</date>
<date year="2009" month="5" day="15">
<event>I went completely mental</event>
</date>
</once>
<</calendar>
So what I would like to do is access the date attrib "year" and then let the user in a form change it to another value.
Thanks you are a star . . . .couldnt see the woods for the trees when looking at examples i found
Anyhow thanks again this is the test code i've setup
PHP Code:
<?php
// Here am loading up the original calendar xml file
$file = "calendar.xml"; //this will actualy be passed when php is invoced
$xml = simplexml_load_file($file); //create the simplexml
// Here am emulating form fields coming in for attributes and event node
// And changing the contents of these in the simplexml string. Will have
// identified the occurance of date i wanna change and passed this through too
// in this case have hard coded the first element ie:[0]
$formyear = "2009";
$formmonth = "5";
$formday = "16";
$formevent = "The day I did it";
$xml->once->date[0]['year'] = $formyear;
$xml->once->date[0]['month'] = $formmonth;
$xml->once->date[0]['day'] = $formday;
$xml->once->date[0]->event = $formevent;
// convert to DOM so we can rewrite the calendar xml file.
$dom_xml = dom_import_simplexml($xml);
$dom = new DomDocument();
$dom_xml = $dom->importNode($dom_xml, true);
$dom_xml = $dom->appendChild($dom_xml);
print $dom->save("calendar.xml")
?>