PHP XML Operation Class domdocument_php tutorial

Source: Internet
Author: User
DOMDocument related content.

Property:

Attributes a list of properties for a storage node (read-only)
ChildNodes List of child nodes of the storage node (read-only)
DataType returns the data type of this node
Definition of a node defined in a DTD or XML schema (read-only)
Doctype the specified 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 returns the parent node (read-only)
Parsed returns whether this node and its child nodes have been parsed (read-only)
Prefix return namespace prefix (read-only)
PRESERVEWHITESPACE specifies whether to preserve whitespace (readable and writable)
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 returns the XML representation of the node and its descendants (read-only)



Method:

AppendChild adds a new child node to the current node, placed after the last child node
CloneNode returns a copy of the current node
CreateAttribute Creating a new property
Createcdatasection Creating a CDATA segment that includes a given data
Createcomment Create a comment node
Createdocumentfragment Creating DocumentFragment objects
CreateElement Creating an Element node
Createentityreference Creating EntityReference Objects
CreateNode Create a node of the given type, name, and namespace
Createporcessinginstruction Creating an action instruction node
createTextNode Creating a text node that includes the given data
getElementsByTagName returns the collection of elements for the specified name
HasChildNodes returns whether the current node has child nodes
InsertBefore inserting a child node before the specified node
Load import XML document at specified location
LoadXML an XML document that imports the specified string
RemoveChild Delete the specified child node from the child nodes list
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 CodeThe code is as follows:



PHP XML processing introduces a
Detailed information One


PHP XML Processing Introduction two
Detailed content Two


PHP XML Processing Introduction Three
Detailed content Three





Copy CodeThe code is as follows:
The first thing to do is to build a DOMDocument object
$xml = new DOMDocument ();

Loading an XML file
$xml->load ("Me.xml");

Get all the post labels
$postDom = $xml->getelementsbytagname ("post");

Looping through post labels
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 that 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)
*
* Tip:
* If the value of the attribute can be->nodevalue with item (*)
* If the attribute tag can be->nodename with item (*)
* If the type of the attribute can be used with 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 JS read XML file Code ajax+xml message
Copy CodeThe code is as follows:
var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
Xmldoc.async = false;
var old speech = "";
function Getxml () {
try{
Xmldoc.load ("Word.xml");
if (xmldoc.documentelement! = null) {
var new speech = Xmldoc.xml;
if (new speak! = Old Speaker) {
Old speech = 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 = = user name. Value) {
Author = "+ author +" ";
}
else{
Author = "+ author +" ";
}
var statement = "" + array [1]+];
New Remarks + = "+ author +" + Speech + "
+""
+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 read = false;
function GetData () {
if (! in read) {
Read in = true;
Getxml ();
Read in = 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) {
Read in = true;
Getxml ();
Read in = false;
}
}
SetTimeout ("submit.disabled = false;", 3000);
Word.focus ();
}

http://www.bkjia.com/PHPjc/320909.html www.bkjia.com true http://www.bkjia.com/PHPjc/320909.html techarticle DOMDocument related content. Properties: 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 Definiti ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.