DOMDocument related content.
Property:
Attributes a list of properties for storage nodes (read-only)
ChildNodes List of child nodes for storage nodes (read-only)
DataType returns the data type of this node
Definition of a node given in a DTD or XML schema (read-only)
Doctype Specify document Type node (read-only)
DocumentElement returns the root element of the document (Readable and writable)
FirstChild returns the first child node of the current node (read-only)
Implementation return 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 and writable)
NodeValue returns the text of the node (readable and writable)
Ownerdocument returns the root document containing this node (read-only)
ParentNode Return parent node (read only)
Parsed returns whether this node and its child nodes have been resolved (read-only)
Prefix return namespace prefix (read only)
PRESERVEWHITESPACE Specifies whether to leave blank (read-write)
PreviousSibling returns the previous sibling node of this node (read-only)
Text returns the textual content of this node and its descendants (readable and writable)
URL returns the URL of the most recently loaded XML document (read-only)
XML representation of the XML return node and its descendants (read-only)
Method:
AppendChild adds a new child node to the current node and places it after the last child node
CloneNode returns the copy of the current node
CreateAttribute Create a new property
Createcdatasection Create a CDATA segment that includes a given data
Createcomment Create a comment node
Createdocumentfragment Create DocumentFragment Object
CreateElement Create an element node
Createentityreference Create EntityReference Object
CreateNode Create a node for a given type, name, and namespace
Createporcessinginstruction Create operation instruction node
createTextNode Create a text node that includes a given data
getElementsByTagName returns the collection of elements of the specified name
HasChildNodes returns whether the current node has child nodes
InsertBefore inserts a child node before the specified node
Load import XML document at specified location
Loadxml an XML document that imports a specified string
RemoveChild deletes the specified child node from the list of child nodes
ReplaceChild to replace the specified child node from the list of child nodes
Save saves the XML file to the specified node
SelectNodes a specified match to the node and returns a list of matching nodes
selectSingleNode a specified match to the node and returns the first matching node
Transformnode the node and its descendants using the specified style sheet
transformNodeToObject converts a node and its descendants using the specified style sheet
Instance gets the Label property. Value:
Me.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<phplamp>
<post>
<title id= "1" >php XML processing Introduction </title>
<details> detailed content 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 III </title>
<details> detailed content 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 post labels
$postDom = $xml->getelementsbytagname ("post");
//Loop traversal post label
foreach ($postDom as $post) {
//Get title tag node
$title = $post->getelementsbytag Name ("title");
/**
* The id attribute to get the title tag is divided into two parts
* 1. Gets the list of all the attributes in title $title->item (0)->attributes
* 2. Get tit The attribute of the ID in Le, because it is in the first place so with item (0)
*
* Tip:
* If the value of the attribute can be->nodevalue with item (*)
* If the attribute can be labeled with item (*)->noden Ame
* If the type of the property can be taken with item (*)->nodetype
/
Echo Id:. $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/>";
}
The following is JS read the XML file code ajax+xml message
Copy Code code as follows:
var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = false;
The old var spoke = "";
function Getxml () {
try{
Xmldoc.load ("Word.xml");
if (xmldoc.documentelement!= null) {
var new speech = Xmldoc.xml;
If (new statement!= old speech) {
Old speeches = new speeches;
var allwords = xmldoc.selectnodes ("List/message");
New statement = "";
for (var i = 0;i < allwords.length;i++) {
var array = allwords[i].text.split ("@");
var author = array [0];
if (author = = user name. Value) {
Author = "<font color= ' Turquoise ' >" + author + "</font>";
}
else{
Author = "<font color= ' Silver ' >" + author + "</font>";
}
var spoke = "<font color= ' Gold ' >" + array [1]+ "</font>";
New Statement + + + author + + + + + </div>
+ "<div style= ' text-align:right;font-size:9px; ' > "
+allwords[i].getattribute ("author"). Substring (0,allwords[i].getattribute ("Author"). LastIndexOf (".") +1)
+"* "
+allwords[i].getattribute ("Time")
+ "</div>";
}
words.innerhtml = new Statement;
Words.scrolltop = Words.scrollheight;
}
}
}
catch (e) {
}
}
var read = false;
function GetData () {
if (! in read) {
= True in read;
Getxml ();
in read = false;
}
SetTimeout ("GetData ()", 3000);
}
GetData ();
Submit.onclick = function () {
Submit.disabled = true;
if (Word.value!= "") {
var xmlHttp = new ActiveXObject ("Microsoft.XMLHTTP");
Xmlhttp.open ("Get", "Save.php?name=" +encodeuricomponent (user name. Value) + "&word=" +encodeuricomponent (Word.value), true);
Xmlhttp.setrequestheader ("Content-type", "text/html; Charset=utf-8");
Xmlhttp.send (NULL);
Word.value = "";
if (! in read) {
= True in read;
Getxml ();
in read = false;
}
}
settimeout ("submit.disabled = false;", 3000);
Word.focus ();
}