Modify XML to specify the contents of a tag C # gets an XML node tag in C # XML NULL tag Tencent QQ XML message label

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

  • Related Article

    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.