DOMDocument related content. Property: Attributes A list of properties for a storage node (read-only) ChildNodes a list of child nodes of the storage node (read-only) DataType returns the data type of this node definition of the node given in the DTD or XML Schema (read-only) Doctype Specifies the document type node (read-only) documentelement returns the root element of a document (read-write) FirstChild returns the first child node of the current node (read-only) implementation returns Xmldomimplementation object LastChild returns the last child node of the current node (read-only) nextSibling returns the next sibling node of the current node (read-only) NodeName returns the name of the node (read-only) NodeType returns the type of the node (read-only) nodeTypedValue Storage node value (readable) nodevalue returns the text of the node (read-write) ownerdocument returns the root document containing this node (read-only) ParentNode returns the parent (read-only) parsed returns whether this node and its child nodes have been parsed (read-only) Prefix returns the namespace prefix (read-only) preservewhitespace specifies whether to preserve whitespace (read-write) previoussibling returns the previous sibling node (read-only) in this node the text content (read-write) URL that returns this node and its descendants Returns the URL of the most recently loaded XML document (read-only) XML returns the XML representation of the node and its descendants (read-only) method: AppendChild Adds a new child node to the current node, CloneNode returns a copy of the current node after the last child node CreateAttribute Create a new property Createcdatasection Create a CDATA segment that includes the given data createcomment create a comment node createdocumentfragment Create a DocumentFragment object createelement create an element node Createentityreference create a EntityReference object CreateNode Create a node of the given type, name, and namespace Createporcessinginstruction Create an action instruction node createTextNode create a text node that includes the given data getelementsbytagnAME returns the collection of elements of the specified name HasChildNodes returns whether the current node has child nodes insertbefore insert a child node before the specified node Load imports the XML document at the specified location LoadXML the XML document that imports the specified string removechild from Removes the specified child node from the child node list replacechild the specified child node from the list of child nodes save saves the XML file to the specified node selectnodes the specified match to the node and returns a list of matching nodes selectSingleNode Makes a specified match to the node and returns the first matching node transformnode the node and its descendants using the specified style sheet transformNodeToObject uses the specified style sheet to get the label properties for the node and its descendants transformation instance. Value: Me.xml Copy the code code as follows: <?xml version= "1.0" encoding= "Utf-8"?> <phplamp> <post> <title id= "1" >php XML processing Introduction </title> <details> Detail One </details> </post> <post> <title id= "2" >php XML processing Introduction two </ title> <details> details two </details> </post> <post> <title id= "3" >php XML processing introduction three </title > <details> Details three </details> </post> </phplamp> copy code code as follows://First to build a DOMDocument object $xml = new DOMDocument (); Load XML file $xml->load ("Me.xml"); Get all the post labels $postDom = $xml->getelementsbytagname ("post"); Loop through the Post label foreach ($postDom as $post) {//Get the title tag node $title = $poSt->getelementsbytagname ("title"); /** * To get the id attribute of the title tag, go to section two * 1. Gets a list of all the attributes in the title, which is $title->item (0)->attributes * 2. Gets the attribute of the ID in the title, because it is in the first place so with item (0) * Small hint: * If the value of the attribute can be used with item (*)->nodevalue * If the tag of the attribute can be used with item (*)->nodename * You can use the item (*)->nodetype */echo "ID:" If the type of the attribute is taken. $title->item (0)->attributes->item (0)->nodevalue. "<br/>"; echo "Title:". $title->item (0)->nodevalue. "<br/>"; echo "Details:". $post->getelementsbytagname ("Details")->item (0)->nodevalue. "<br/><br/>"; }
PHP operation in XML file verbose