Php XML operation (read) encapsulation class instance

Source: Internet
Author: User
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!

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.