First, PHP DOM
1. Main categories:
DOMDocument: Document Class--$dom->new DOMDocument (' 1.0 ', ' gb2312 ')
Domnodelist: Node List class--$dom->getelementsbytagname (")
DomElement: Element Class--$dom->getelementsbytagname (")->item (0); $dom->documentelement (Root node)
Domnode: Node class
node additions and deletions change (To find the parent node first)
$dom->load (' Aa.xml ')
$dom->createelement (' name ' [, ' value ']);
$son = $dom->createcdatasection (");
$parent->appendchild ($son);
$parent->removechild ($son);--delete node
$parent->replacechild ($new, $old);--replace node
$dom->savexml (' Aa.xml ')
$dom->save (' Aa.xml ')
Property manipulation
$element->setattribute (' name ', ' value '); Add or modify property values
$element->getattribute (' name ');--Get the value of the property
$element->hasattribute (' name ');--to determine if there is a property
$element->removeattribute (' name ')--delete attribute
Second, SimpleXML
The returned XML variable is an instance of the SimpleXMLElement class//This object represents the root element in the XML $xml=simplexml_load_file (' Demo05.xml '); Echo $xml->person[1] ->name. ' <br> '; Echo $xml->person[1]->age. ' <br> ';
$xml =simplexml_load_file (' demo05.xml ');
$xml->children ();--represents all child nodes of the root node
To add a node:
$person = $xml->addchild (' person ');
$person->addchild (' name ', ' Tom ');
$person->addchild (' Age ', ' 29 ');
$xml->asxml (' demo05.xml ');
Add Property
$xml =simplexml_load_file (' demo05.xml ');//Add the id attribute to the 3rd person with a value of P103$xml->person[2]->addattribute (' id ', ' p103 '); $ Xml->asxml (' Demo05.xml ');
Third, XPATH
Ads