Find and modify XML files using XPath-PHP source code

Source: Internet
Author: User
XPath searches for and modifies php code for XML files:

     
         
  11        
  
   
Content1
          
  
   
2009-10-11
      
     
         
  Title2        
  
   
Content2
          
  

      
 */If (! Function_exists ('L') {function l () {echo'
***********************************
';}} If (file_exists ('test10 _ 12. xml ') {$ xml = simplexml_load_file ('test10 _ 12. xml '); // use the xpath method to find the node location $ query = $ xml-> xpath (' // title [@ name = "t1"]/ancestor :: item '); var_dump ($ query); // debug l (); // test the addition of a subnode new $ query [0] under the title node-> title-> addChild ('new', 'new '); // test the addition of the attribute fuck $ query [0] under the title node-> title-> addAttribute ('fuck', 'fuck '); // Test and modify the content node value to hello, world $ query [0]-> content = 'Hello, world'; // not explained, you know $ query [0]-> asXML ("10.xml");}/* End of PHP */

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.