A small question about xml processing in php

Source: Internet
Author: User
A small question about php processing xml
Encountered a small problem
Assume that the content of a variable is as follows:
$ Test ="

 

  11111111

  

  11111111

  

  
   
1111

  

  text

  

  test

  

  
   
111111

  

 ";

$ PostObj = simplexml_load_string ($ test, 'simplexmlelement', LIBXML_NOCDATA );
Use simplexml_load_string to read xml into the variable
$ PostObj-> addChild ("id", "123 ");
I added an element
How can we restore the content in the variable to xml format?


Reply to discussion (solution)

You can write it back.
$ Test = $ postObj-> saveXML ();

However, please note that you have the LIBXML_NOCDATA parameter when you open it, so there will be no CDATA nodes written back.

You can write it back.
$ Test = $ postObj-> saveXML ();

However, please note that you have the LIBXML_NOCDATA parameter when you open it, so there will be no CDATA nodes written back.
Confused. I just read the PHP SimpleXML function for a long time.
I always thought that saveXml is used to save xml as a file... thank you.

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.