This article mainly introduces the XML operation (read) encapsulation class implemented by php, and provides an xml format file example, combined with the complete instance form, This article analyzes the related operation skills for php to traverse and read data nodes in xml format. For more information, see the following example to describe the XML operation (read) encapsulation class implemented by php. We will share this with you for your reference. The details are as follows:
Normal | DR
Wondershare Vedio Convertor
Wondershare
Customize | Affiliate
143724583
0 | 1
1464646.mac-transpod-lite_full879.dmg
11642
1 | 0
1 | 0
Jump | Hide | Disable
1 | 0
1 | 0
#
#
#
#
#
#
#
#
#
#
#
#
Encapsulate the xml operation class:
LoadXML ($ xmlNewStr);} else {$ xmlObj-> load ($ xml);} return $ xmlObj ;} /*** get a label node * @ param $ parentnode parent node * @ param $ tagName tag name // case insensitive * @ return node object */protected function _ getNode ($ parentNode, $ tagName) {$ childNodes = $ this-> _ getNodes ($ parentNode); foreach ($ childNodes as $ node) {$ nodeName = strtolower (trim ($ node-> nodeName); $ tagName = strtolower (trim ($ tagName); if ($ nodeName = $ TagName) {return $ node;} return NULL ;} /*** get xml subnode * @ param $ parentNode parent node * @ param $ tagName subnode label // case insensitive */protected function _ getNodes ($ parentNode, $ tagName = '') {$ nodes = array (); if ($ tagName) {$ nodes = $ this-> _ getSpecialNodes ($ parentNode, $ tagName );} else {$ nodes = $ this-> _ getAllNodes ($ parentNode);} return $ nodes ;} /*** get all nodes * @ param $ parentNode parent node */protected functi On _ getAllNodes ($ parentNode) {$ nodes = array (); foreach ($ parentNode-> childNodes as $ node) {if ($ node-> nodeType = 1) {$ nodes [] = $ node;} return $ nodes ;} /*** get the node of the specified label * @ param $ parentNode parent node * @ param $ tagName node name */protected function _ getSpecialNodes ($ parentNode, $ tagName) {$ nodes = array (); $ tagName = strtolower (trim ($ tagName); foreach ($ parentNode-> childNodes as $ node) {$ nodeName = Strtolower (trim ($ node-> nodeName); if ($ node-> nodeType = 1 & $ nodeName = $ tagName) {$ nodes [] = $ node;} return $ nodes ;} /*** get node attribute value ** @ param $ node object * @ param $ attrName node name // case insensitive */protected function _ getAttr ($ node, $ attrName) {$ attrName = strtolower ($ attrName); foreach ($ node-> attributes as $ attr) {$ nodeName = strtolower ($ attr-> nodeName ); // $ nodeValue = strtolower ($ attr-> n OdeValue); $ nodeType = strtolower ($ attr-> nodeType); if ($ nodeType = 2 & $ nodeName = $ attrName) {unset ($ attrName, $ nodeName, $ nodeType); return $ attr-> nodeValue ;}} return '';}}?>
For more articles about php XML operations (read) encapsulation instances, please follow the PHP Chinese network!