PHP XML Operation Class DOMDocument

Source: Internet
Author: User
Have to write one yourself. The operation of XML has never been used. Here are the XML operation classes that you have collected

DOMDocument related content.

Property:
Attributes---> Storage node Property list (read-only)
ChildNodes List of child nodes---> Storage nodes (read-only)
DataType---> Returns the data type of this node
Definition---> Definitions of nodes given in DTD or XML Schema (read-only)
Doctype---> Specify document Type node (read-only)
DocumentElement---> returns the root element of a 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---> Return the name of the node (read-only)
NodeType---> Return type of 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 parsed (read-only)
Prefix---> Return namespace prefix (read-only)
PreserveWhitespace---> Specify 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 XML representations of nodes and their 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---> Create a new property
Createcdatasection---> Create CDATA Segments that include the given data
Createcomment---> Create a comment node
Createdocumentfragment---> Create documentfragment objects
CreateElement---> Create an element node
Createentityreference---> Create EntityReference objects
CreateNode---> Create a node of the given type, name, and namespace
Createporcessinginstruction---> Create Operation instruction Node
createTextNode---> Create 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 the specified location
LoadXML---> Import XML document for the specified string
RemoveChild---> Remove a specified child node from the child nodes list
ReplaceChild---> Replace the specified child nodes from the child nodes list
Save---> Save XML file to the specified node
SelectNodes---> matches a specified node and returns a list of matching nodes
selectSingleNode---> Specify a match to the node and return the first matching node
Transformnode---> Convert a node and its descendants using the specified style sheet
transformNodeToObject---> Convert a node and its descendants using the specified style sheet
Instance gets the Label property. Value:

Me.xml

View Code

1 
 
    2 
 
  
   
    3 
  
   
    
     4 
   
    PHP XML processing introduces a  5 
   
    
     
    Detail
   one
      6 
  
     7 
  
   
    
     8 
   
    PHP XML Processing Introduction two  9 
   
    
     
    details two
   
     
  
    
  
   
    
    12 
   
    PHP XML Processing Introduction Three 
  
    
     
    details
   :
     
    15 
 
  


View Code

1//First to build a DOMDocument object  2 $xml = new DOMDocument ();  3//Load XML file  4 $xml->load ("Me.xml");  5//Get all post label  6 $postDom = $xml->getelementsbytagname ("post");  7//Loop traverse post label  8 foreach ($postDom as $post) {  9//Get title tag node $title = $post->getelementsbytagname ("Titl E "); 11/** 12 * To get the id attribute of the title tag, go to two part 13 * 1. Gets a list of all the attributes in the title, which is $title->item (0)->attributes 14 * 2. Gets the attribute of the ID in the title because it is in the first place so with the item (0) 15 * 16 * Tip: 17 * If the value of the attribute can be used with item (*)->nodevalue 18 * If the tag of the attribute can be used with item (*)->nodename 19 * 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

JavaScript code

 1 var xmldoc = new ActiveXObject ("Microsoft.XMLDOM"); 2 Xmldoc.async = false; 3 var old speech = "";             4 function Getxml () {5 try {6 xmldoc.load ("Word.xml"); 7 if (xmldoc.documentelement! = null) {8 var new speech = Xmldoc.xml; 9 if (New speak = Old spoke) {10 old speech = new statement; var allwords = Xmldoc.selectnodes ("List/mes Sage "); 12 new statement =" "; for (var i = 0; i < allwords.length;                     i++) {array of var = allwords[i].text.split ("@"); var author = array [0];16 if (author = = user name. value) {17 Author = "+ author +" ";}19 Els                      e {20 Author = "+ author +" ";}22 var statement =" "+ array [1] +" "; 23 New Remarks + = "+ author +" + Speech + "+24" "+25 allwords[i].getattr Ibute ("author"). Substring (0, Allwords[i].getattriBute ("author"). LastIndexOf (".") + 1) +26 "*" +27 Allwords[i].getattribute ("Time") +28 "";}30 words.innerhtml = new speech; Words.scrollto p = words.scrollheight;32}33}34} (e) {}37}38 in var read = false;40 functio n GetData () {if (! Read) {42 read = true;43 getxml (); 44 read = False;45}46 setTimeout (" GetData (),}48 (), GetData (), Submit.onclick = function () {submit.disabled = true;52 if (word.value!) = "") {xmlHttp var = new ActiveXObject ("Microsoft.XMLHTTP"); Xmlhttp.open ("GET", "save.php?name=" + E Ncodeuricomponent (username. Value) + "&word=" + encodeURIComponent (Word.value), true), Xmlhttp.setrequestheader ("C Ontent-type "," text/html; Charset=utf-8 "); Xmlhttp.send (null); word.value =" ";" "". "(! Read) {59 Read = True; Getxml (); 61 read = false;62}63}64 setTimeout ("submit.disabled = false;", 3000 ); Word.focus (); 66}
  • 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.