How can I modify an xml file in php?

Source: Internet
Author: User
How can I modify an xml file in php?
 
 
  
   
. Html/article/hardware/008.html
  
  
   
Http://www.niutuku.com // </list>
   
    
Http://www.niutuku.com // </list>
    
     
Http://www.niutuku.com // </list>
    
   
  
 
 
  
3
 
 

The above is the xml file I want to modify. Four in And smallinfo attributes, please help me.


Reply to discussion (solution)

This mainly involves xml DOM operations. let's take a look at this content.

Use xml DOM

if ( file_exists ( 'out.xml' )) {     $xml  = simplexml_load_file ( 'out.xml' );      foreach ($xml->pic->list as $key => $value) {      $attr = (array) $value->attributes ();      var_dump($attr['@attributes']['smallinfo']);      } } else {    exit( 'Failed to open test.xml.' );}
We recommend that you use simple_html_dom or phpQuery to change the value.

$ S = <XML
   
   
    
     
. Html/article/hardware/008.html
    
    
     
Http://www.niutuku.com // </list>
     
      
Http://www.niutuku.com // </list>
      
       
Http://www.niutuku.com // </list>
      
     
    
   
   
    
3
   
   XML; $ xml = simplexml_load_string ($ s); for ($ I = 0; $ I
   
    
Pic-> list); $ I ++) {$ xml-> pic-> list [$ I] = $ I; $ t = $ xml-> pic-> list [$ I]-> attributes (); $ t ['smallpath'] = $ I ;} echo $ xml-> asXML ();
   
   
   
    
     
0
    
    
     
1
    
    
     
2
    
    
     
3
    
   
   
    
3
   
   

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.