I have to write a. XML file myself, but I have never used it. below is the content related to the XML operation class DOMDocument.
Attribute:
Attribute list of the Attributes storage node (read-only)
List of child nodes of the childNodes storage node (read-only)
DataType returns the data type of this node
Definition defines nodes in DTD or XML mode (read-only)
Doctype specifies the file type node (read-only)
DocumentElement returns the root element of the document (read/write)
FirstChild returns the first child node of the current node (read-only)
Implementation returns the 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: return the node name (read-only)
NodeType return node type (read-only)
NodeTypedValue stores node values (read/write)
NodeValue returns the node text (read/write)
OwnerDocument returns the root document containing this node (read-only)
ParentNode returns the parent node (read-only)
Parsed: returns whether the node and its subnodes have been Parsed (read-only)
Prefix returns the namespace Prefix (read-only)
PreserveWhiteSpace specifies whether to retain white space (read/write)
Previussibling returns the previous sibling node of this node (read-only)
Text returns the Text content of the node and its descendants (read/write)
Url returns the URL of the recently loaded XML document (read-only)
Xml returns the XML representation of the node and its descendants (read-only)
Method:
AppendChild adds a new subnode to the current node, which is placed after the last subnode
CloneNode returns the copy of the current node
CreateAttribute
CreateCDATASection create CDATA segments that contain the given data
CreateComment create a comment node
CreateDocumentFragment create a DocumentFragment object
CreateElement: create an element node
CreateEntityReference: Create an EntityReference object
CreateNode creates nodes of the given type, name, and namespace.
CreatePorcessingInstruction
CreateTextNode: create a text node that includes the given data
GetElementsByTagName returns the set of elements with the specified name.
HasChildNodes: returns whether the current node has subnodes.
InsertBefore inserts a subnode before a specified node
Load import the XML document at the specified position
LoadXML import the XML document of the specified string
RemoveChild deletes a specified subnode from the subnode list.
ReplaceChild replaces the specified child node from the child node list
Save the XML file to the specified node
SelectNodes matches the specified node and returns the list of matched nodes.
SelectSingleNode matches the specified node and returns the first matching node.
TransformNode converts nodes and their descendants using the specified style table.
TransformNodeToObject converts nodes and their descendants using the specified style table
The instance obtains the tag attributes. value:
Me. xml
The code is as follows:
Php xml processing 1
Details 1
Php xml processing 2
Details 2
Php xml processing 3
Details 3
The code is as follows:
// Create a DOMDocument object first
$ Xml = new DOMDocument ();
// Load the Xml file
$ Xml-> load ("me. xml ");
// Obtain all post tags
$ PostDom = $ xml-> getElementsByTagName ("post ");
// Cyclically traverse the post tag
Foreach ($ postDom as $ post ){
// Obtain the Title label Node
$ Title = $ post-> getElementsByTagName ("title ");
/**
* The Id attribute of the Title tag to be obtained must be divided into two parts.
* 1. obtain the list of all attributes in the title, that is, $ title-> item (0)-> attributes
* 2. obtain the attribute of the id in the title. because it is in the first place, item (0) is used)
*
* Tips:
* If you take the attribute value, you can use item (*)-> nodeValue
* If an attribute tag is used, you can use item (*)-> nodeName
* If the attribute type is used, you can use item (*)-> nodeType
*/
Echo "Id:". $ title-> item (0)-> attributes-> item (0)-> nodeValue ."
";
Echo "Title:". $ title-> item (0)-> nodeValue ."
";
Echo "Details:". $ post-> getElementsByTagName ("details")-> item (0)-> nodeValue ."
";
}
The following is the code for js to read xml files: ajax + xml message
The code is as follows:
Var xmldoc = new ActiveXObject ("Microsoft. XMLDOM ");
Xmldoc. async = false;
Old var statement = "";
Function getxml (){
Try {
Xmldoc. load ("word. xml ");
If(xmldoc.doc umentElement! = Null ){
Var New Speech = xmldoc. xml;
If (new! = Old statement ){
Old statement = new statement;
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 = Username. value ){
Author = "" + author + "";
}
Else {
Author = "" + author + "";
}
Var statement = "" + array [1] + "";
New speech + ="
"+ Author +" "+ Speaker +"
"
+"
"
+ Allwords [I]. getAttribute ("author"). substring (0, allwords [I]. getAttribute ("author"). lastIndexOf (".") + 1)
+ "*"
+ Allwords [I]. getAttribute ("time ")
+"
";
}
Words. innerHTML = new speech;
Words. scrollTop = words. scrollHeight;
}
}
}
Catch (e ){
}
}
Var reading = false;
Function getdata (){
If (! Reading ){
Reading = true;
Getxml ();
Reading = 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 (Username. value) +" & word = "+ encodeURIComponent (word. value), true );
XmlHttp. setRequestHeader ("Content-Type", "text/html; charset = utf-8 ");
XmlHttp. send (null );
Word. value = "";
If (! Reading ){
Reading = true;
Getxml ();
Reading = false;
}
}
SetTimeout ("submit. disabled = false;", 3000 );
Word. focus ();
}