DOMXML function notes_PHP tutorial
/**
* DOMXML function notes
* After connecting php_domxml.dll
* Use get_defined_functions() to get domxml support functions
*
* Currently domxml does not support language declarations other than iso-8859-1
* Supported
* Not supported
* Therefore, it needs to be transformed into this, which may require
* utf8_encode() utf8_decode() functions for processing
*
* function list
* string domxml_version(void) Returns the version number of domxml
* object xmldoc(string str) Creates an XML Domdocument object from a string
* object xmldocfile(string filename) Creates an XML Domdocument object from a file
* object xmltree(string str) Parses the xml document and returns the tree structure, which cannot be changed with the domxml function XML string. There is a problem with this function. It will add an extended ascii character in front of the first Chinese character, in the form of nnn;
* domxml_node_attributes
* domxml_elem_get_attribute
* domxml_elem_set_attribute
* array domxml_node_children(object doc |node) Return child node
* domxml_node_new_child
* object domxml_node(string name) Create a node node
* domxml_node_unlink_node
* int domxml_node_set_content(resource doc,string content) Set node content
* object domxml_new_xmldoc(string version) Create a new empty XML object
* xpath_new_context
* xpath_eval
* xpath_eval_expression
* xptr_new_context
* xptr_eval
* object domxml_root(object doc) Return the root node
* array domxml_attributes(resource note) Get node attributes
* object domxml_get_attribute(resource doc,string name) Read attributes
* domxml_getattr
* object domxml_set_attribute(resource doc,string name,string value) Add attribute
* domxml_setattr
* array domxml_children(object doc|node) Return child node
* resource domxml_new_child(string name,string content) Add child node
* domxml_unlink_node
* set_content
* new_xmldoc
*
*/
?>
<br><?php<br>// Document xml source tree.xml content<br> $testxml = '<br><?xml version="1.0" encoding="GB2312"?> <br><root><br><note>When reading the xml document, the processor will form a tree , we call it the source tree. The tree has various types of nodes in the table. <br></note><br><title>The source tree has node</title><br><table><br><tr><th>Node type</th> <th>Description</th></tr><br><tr><td>Root (root)</td><td>This is the root node of the tree. Can appear anywhere on the tree. The root node has only one child node, and the child node refers to the document element node in the xml document. </td></tr><br><tr><td>Element (element)</td><td>This node is used for any element in the document. The child nodes of an element node can be element nodes, annotation nodes, processing information nodes, and text nodes of its content. </td></tr><br><tr><td>Text(text)</td><td>All text appearing in the document are grouped into text nodes. A text node cannot have any immediately preceding or following sibling nodes that are also text nodes. </td></tr><br><tr><td>Attribute (attribute)</td><td>Each element node has its own set of attached attribute nodes. Default property values are handled in the same way as specified properties. None of these nodes have child nodes. </td></tr><br><tr><td>Namespace(name)</td><td>For every element starting with xlmns: and an attribute node, there is a Name space node. These nodes have no child nodes. </td></tr><br><tr><td>Processing Instruction(processing instruction)</td><td>Each processing instruction has a separate node. None of these nodes have child nodes. </td></tr><br><tr><td>Comment (Comment)</td><td>Each has a comment node. None of these nodes have child nodes.</td></tr><br></table><br></root><br>';<br><br>echo "domxml version:".domxml_version();<br>echo "<p> </p>";<br>// xmltree domxml_dumpmem<br>$filename = "xml source tree.xml";<br>//$filename = "resume.xml";<br>$fp = fopen($filename,"r"); <br>$inXML = fread($fp,filesize($filename)); <br>fclose($fp); <br>// Delete language setting Define<br>//$inXML = str_replace(' encoding="GB2312"',"",$inXML);<br>$inXML = eregi_replace(' encoding="[a-z0-9_-]+"', "",$inXML);<br><br>$doc = xmltree($inXML); // Use xmltree to parse <br>$myxml = $doc->dumpmem(); // Convert to string, header For xml version = "1.0" <br> // If you execute it again, your head will become xml version = "1.0" encoding = "ISO-8859-1" <br> // $ Myxml = EREGI_REPLE ('[[[' [[ 0-9]+;',"",$myxml); // Delete<br>echo "Use xmltree to parse<br>";<br>echo "<textarea cols=60 rows=5>$myxml< /textarea><br>";<br>//print_r($doc); // You can see the entire tree or use var_dump($doc);<br><br>// xmldoc<br>$doc = xmldoc($inXML); <br>$myxml = $doc->dumpmem();<br>echo "Use xmldoc to parse<br>";<br>echo "<textarea cols=60 rows=5> $myxml</textarea><br>";<br>//print_r($doc); // Only the root node can be seen<br><br>// domxml_new_xmldoc<br>$doc = domxml_new_xmldoc("1.0 ");<br><br>$root = $doc->add_root("HTML");<br>$head = $root->new_child("HEAD", "");<br>$head ->new_child("TITLE", "DOMXML Test 0");<br>$head->new_child("TITLE", "DOMXML Test 1");<br>$head->set_attribute("Language" , "ge");<br>domxml_node_set_content($head,"ppp"); // Set the content of the node, multiple executions are superimposed<br>domxml_node_set_content($head,"ttt");<br><br>// It is a function with only 1-2 "_" in the function name, which can be used as an object method <br><br>$myxml = $doc->dumpmem();<br>echo "custom xml<br>";<br>echo "<textarea cols=60 rows=5>$myxml</textarea><br>";<br><br>// Traversal of nodes<br>/** <br> Node Structure<br> DomElement Object<br> type = 1<br> tagname = Node Name<br> DomText Object<br> type = 3<br> content = Section Content Point<br> DomCData Object<br> type = 4<br> content = section content point<br><br> DomProcessingInstruction Object<br> type none<br> target = processing instruction<br> data = parameter<br><br>*/<br>$ar[] = $doc->root(); // Get the root node <br>$ar[] = $ar[count($ar)-1]->children ();<br>$ar[] = $ar[count($ar)-1][0]->children();<br><br>// Function domxml_children() cannot return node parameters<br>//To return node parameters, you need to use domxml_attributes()<br>//var_dump(domxml_attributes($head));<br>//print_r($ar[1][0]->attributes());<br>//print_r($ar);<br><br>function xml_dumpmem($xmldoc) {<br> static $mode = 0;<br> $xmlstr = "";<br> // Get the node and save it in In the array<br> if(get_class($xmldoc) == "DomDocument") {<br> $xmlstr = '<?xml version="1.0" encoding="gb2312"?>'."n";<br> if(count($xmldoc->children) == 1) // Root node, no other members <br> $docs[] = $xmldoc->root();<br> else<br> $ docs = $xmldoc->children(); // Root node, with other members <br> }else {<br> $docs = $xmldoc->children(); // General node <br> }<br><br>// echo __LINE__."<br>";<br> foreach($docs as $doc) {<br> $attr = $doc->attributes();<br> switch($doc ->type) {<br> case 1:<br> $xmlstr .= "<{$doc->tagname}"; // Tag header<br> if($attr) {<br> foreach( $attr as $key)<br> $xmlstr<br> $xmlstr .= ">"; // End of tag <br> $xmlstr .= xml_dumpmem($doc); // Enter child node <br> $xmlstr .= "</{$doc-> ;tagname}>"; // Close tag<br> break;<br> case 3:<br> $xmlstr .= $doc->content;<br> case 4:<br> $xmlstr .= "<![CDATA][";<br> $xmlstr default:<br> if(get_class($doc) == "DomProcessingInstruction") {<br> $xmlstr .= "<?{$doc->target}";<br> $xmlstr .= " {$ doc->data}?>n";<br> }<br> break;<br> }<br> }<br> return $xmlstr;<br>}<br><br>if(1) {<br> $filename = "resume.xml";<br>// $filename = "resume.xsl";<br> $filename = "xml source tree.xml";<br> $fp = fopen($ filename,"r"); <br> $inXML = fread($fp,filesize($filename)); <br> fclose($fp); <br> $inXML = eregi_replace(' encoding="[a-z0 -9_-]+"',"",$inXML);<br>// $doc = xmltree($inXML); // Use xmltree to parse <br> $doc = xmldoc($inXML); // Use xmldoc Parse<br>}<br><br>// Cannot be used to parse xsl documents<br><br>$myxml = xml_dumpmem($doc);<br>echo "Write your own dumpmem and you won’t go wrong<br> ;";<br>echo "<textarea cols=60 rows=5>$myxml</textarea><br>";<br>print_r($doc);<br><br>?><br>
http://www.bkjia.com/PHPjc/313922.html
www.bkjia.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.
