Asxml (' file.xml ') saved files after processing XML in SimpleXML, no format layout? One line looks at the Bible.

Source: Internet
Author: User
Tags addchild
Build an XML file in SimpleXML,

Xml->addchild ()

Xml->addattribute ()
The Horse of God,

Save time Xml->asxml (' file.xml '); The resulting XML file is displayed on one line,

Look and want to be crazy, too disorderly pull.

Can't he just wrap it up and indent it?


Reply to discussion (solution)

It seems that there is no ... Only manual substitution plus line break is available:

Add one sentence: $xml->formatoutput = true;

Add one sentence: $xml->formatoutput = true;

I started with simplexml.
$xml = simplexml_load_string ($xmlstring);
AddChild
AddAttribute

Then in order to format this
$xmlDoc = new DOMDocument (' 1.0 ');
$xmlDoc->formatoutput = true;
$xmlDoc->loadxml ($xml->asxml ());

$xml _file_save = fopen (' File\file.xml ', "w");//Open file ready to write
Fwrite ($xml _file_save, $xmlDoc->savexml ());
Fclose ($xml _file_save);//Close file

As a result, it is still the same, and there is no wrapping and indentation formatting in the file.






It seems that there is no ... Only manual substitution plus line break is available:

In the simplexml, how to add it? Can it be treated as an existing string?

Read the manual tidy module

Wrapping, indenting is meaningless for XML, just adding the size of the XML document in vain (it's already big enough)
What you see in any XML editor (including your browser) is formatted content

  • 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.