Modify XML to specify label contents (I'm a space that removes the specified label content)
In fact, it is a very simple method, the need for the pot friends to take directly.
Test.xml
XML version= "1.0" encoding= "UTF-8"?><DOCUMENT><Item><Key>It's a good habit to record a blog
Key><URL>Http://www.cnblogs.com/keerdi/p/5465549.html
URL><title>Remove whitespace from XML
title><content>It's important to develop a good habit, which is a file with a space,
content><Date>2016-1-12
Date>!-- Item ; < Item ; < Key ; join us to write a blog !-- key ; < URL ; http://www.cnblogs.com/keerdi/p/5465549.html !-- url > < title ; blogging can enhance memory capacity !-- title ; < content ; generally installed Linux system are English interface, online check a variety of statements have, I only do the following configuration is good, download a Chinese package, change i18 n is done, and not so complex !-- Span>content , <, date , 2016-1-12 ,!--
date , !-- item , !-- /span--> DOCUMENT ;
update.php
PhpfunctionActiongetxml () {$xmlpath= ' Test.xml '; $xml=NewDOMDocument ("1.0", "UTF-8"); $xml->load ($xmlpath); $root=$xml-documentelement; //get the total number of labels$nodes=$root->getelementsbytagname ("Item"); for($i= 0;$i<=$nodes->length;$i++){ //Specify the content tag and get the contents tag to remove all spaces through the Deltrim () method$str=$xml->getelementsbytagname ("Content")->item ($i); //$str->nodevalue = "Here is the content to be modified";$str->nodevalue =$this->deltrim ($str-nodevalue); $xml->save ("Test.xml"); } } //Remove SpacesfunctionDeltrim ($object) { $search=Array("," "," \ T "," \ n "," \ R ")); $replace=Array("", "", "", "", ""); returnStr_replace($search,$replace,$object); }?>
The above describes the modification of XML specified tag content, including XML, tag content, I hope the PHP tutorial interested in a friend helpful.