Is there no formatting for the files saved by asXML ('File. XML') after processing XML in SimpleXML? One line looks like Tianshu.

Source: Internet
Author: User
Is there no formatting for files saved by asXML (file. XML) after processing xml in SimpleXML? One line looks like Tianshu, SimpleXML, to build an xml file,

Xml-> addChild ()

Xml-> addAttribute ()
Shenma's,

When saving the disk, xml-> asXML ('File. XML'); the xml file is displayed in one row,

It's crazy to watch and watch.

He cannot wrap the line automatically. what is indentation?


Reply to discussion (solution)

It seems that there is no ..... You must manually replace it with a line break ..

Add the following sentence: $ xml-> formatOutput = true;

Add the following sentence: $ xml-> formatOutput = true;

I started to process it with SimpleXML,
$ Xml = simplexml_load_string ($ xmlstring );
AddChild
AddAttribute

Then, for the format
$ XmlDoc = new DOMDocument ('1. 0 ');
$ XmlDoc-> formatOutput = true;
$ XmlDoc-> loadXML ($ xml-> asXML ());

$ Xml_file_save = fopen ('file \ file. XML', "w"); // open the file to prepare for writing
Fwrite ($ xml_file_save, $ xmlDoc-> saveXML ());
Fclose ($ xml_file_save); // close the file

The result is the same. there is no line break or indent format in the file.






It seems that there is no ..... You must manually replace it with a line break ..

In SimpleXml, how can I add it? Can it be processed as a stored string?

Read manual tidy module

Line breaks and indentation are meaningless for XML, but in vain they increase the size of the XML document (it would be big enough)
What you see in any XML editor (including a browser) is formatted content.

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.