A question about XML

Source: Internet
Author: User
Ask an XML question. this is the XML of an IP security policy, meaning that each user can log on only when the ip address is & lt; iplist & gt, I want to know how to modify and delete a user's ip list. I use DOMDOCUMENT (); & lt ;? Xmlversi ask an XML question
This is the XML of an IP security policy, meaning that each user can only You can log on only when the content is in. I want to know how to modify and delete the ip address list of a user. I use DOMDOCUMENT ();




192.168.1.1
192.168.1.2 // For example, if I want to modify or delete admin ip2, the rest will remain unchanged.
192.168.1.3 // Because the node names are the same, do you want to give Add id
192.168.1.4
192.168.1.5


192.168.1.11
192.168.1.12
192.168.1.13
192.168.1.14
192.168.1.15


192.168.1.21
192.168.1.22
192.168.1.23
192.168.1.24
192.168.1.25



------ Solution --------------------
Tragedy and tragedy. DomDocument is a very standard DOM model. php manual provides detailed methods and examples. why is it lazy?
------ Solution --------------------
PHP code
   
   
    
     
      
192.168.1.1
     
     
      
192.168.1.2
      
     
      
192.168.1.3
      
     
      
192.168.1.4
     
     
      
192.168.1.5
     
    
    
     
      
192.168.1.11
     
     
      
192.168.1.12
     
     
      
192.168.1.13
     
     
      
192.168.1.14
     
     
      
192.168.1.15
     
    
    
     
      
192.168.1.21
     
     
      
192.168.1.22
     
     
      
192.168.1.23
     
     
      
192.168.1.24
     
     
      
192.168.1.25
     
    
   EOF; $ dom = new DOMDocument (); $ ret = $ dom-> loadXML ($ xml, libxml_noblks); $ xpath = new DOMXpath ($ dom ); $ node_list = $ xpath-> query ('/user/username [@ name = "admin"]/iplist'); for ($ I = 0; $ I! = $ Node_list-> length; ++ $ I) {echo $ node_list-> item ($ I)-> nodeValue. PHP_EOL;}?>
------ Solution --------------------
PHP code
$ S = <XML
     
     
      
       
        
192.168.1.1
       
       
        
192.168.1.2
       
       
        
192.168.1.3
       
       
        
192.168.1.4
       
       
        
192.168.1.5
       
      
      
       
        
192.168.1.11
       
       
        
192.168.1.12
       
       
        
192.168.1.13
       
       
        
192.168.1.14
       
       
        
192.168.1.15
       
      
      
       
        
192.168.1.21
       
       
        
192.168.1.22
       
       
        
192.168.1.23
       
       
        
192.168.1.24
       
       
        
192.168.1.25
       
      
     XML; $ dom = new domDocument; $ dom-> loadXML ($ s); $ xpath = new DOMXPath ($ dom ); // use xpath to locate and modify $ p = $ xpath-> query ("// username [@ name = 'admin']/iplist [. = '2017. 168.1.1 '] ")-> item (0); $ p-> nodeValue = 'abc '; // use xpath to locate and delete $ p = $ xpath-> query ("// username [@ name = 'admin']/iplist [. = '2017. 168.1.2 '] ")-> item (0); $ p-> parentNode-> removeChild ($ p); echo $ dom-> saveXML ();

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.