source file
<?xml version= "1.0" encoding= "Utf-8"?>
<root>
<endTime>2016-08-01</endTime>
<content> File Contents </content>
</root>
$file = ' callboard.xml ';
Query XML-----------------------
$doc =new DOMDocument ();//Instantiate a pair of images
$doc->load ($file);//Load file
$data =array ();
$time = $doc->getelementsbytagname ("EndTime");//Gets the element is the title
$dateTime = $time->item (0)->nodevalue;//Gets the value for the specified element
$content = $doc->getelementsbytagname ("content");//Gets the element is the title
$dataContent = $content->item (0)->nodevalue;//Gets the value for the specified element
Update and create-------------------
If (file_exists ($file))//Determine if file exists
{
//update content if it exists
$doc =new DOMDocument ();//Instantiate a pair like
$doc->load ($file);//Load file
$resultDate = $doc->getelementsbytagname ("EndTime");//Get element is Datenumber
$resultDate->item (0)->nodevalue=$_post[' time '];//assigning a value to a specified element
$resultBall 1= $doc->getelementsbytagname ("content");//Get element is Ball1
$resultBall 1->item (0)->nodevalue=$_post[' Content '];//assigns a value to the specified element
$doc->save ($file);// Use this method when it is useful to modify
}
Else
{
Create a file if it does not exist
$doc =new DOMDocument (' 1.0 ', ' utf-8 ');//Declaration is XML
$doc->formatoutput=true;//Format output
$root = $doc->createelement (' root ');//Create root element
$endTime = $doc->createelement ("EndTime", $_post[' time ');//Create element Datenumber and assign value $arr[' resultdate '] content
$content = $doc->createelement ("content", $_post[' content ');//Create element Ball1 and assign value $arr[' resultBall1 '] content
$root->appendchild ($endTime);//$content element contains $datenumber elements
$root->appendchild ($content);//$content element contains $ball1 elements
$doc->appendchild ($root);//end establishment of root meta-cable
$doc->save ($file);//Generate Xml.xml file
}
PHP XML file additions and deletions to change