Jump to content

How to add line breaks to PHP generated XML files


letoii

Recommended Posts

I am constructing an XML file with PHP. I read information from a template XML file and then add elements and save it.

 

The line breaks from the template are preserved in the saved file, but all the new elements are on one line. Is there a way to break them up so it is easier to read the file?

 

Here is the original template:

<InternationalShippingServiceOption> 
  <ShippingService> token </ShippingService>
  <ShippingServiceAdditionalCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceAdditionalCost>
  <ShippingServiceCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceCost>
  <ShippingServicePriority> int </ShippingServicePriority>
</InternationalShippingServiceOption>

 

Here is the saved information (all the ShipToLocation elements on one line):

<InternationalShippingServiceOption> 
  <ShippingService>StandardInternational</ShippingService>
  <ShippingServiceAdditionalCost currencyID="CurrencyCodeType">26.994</ShippingServiceAdditionalCost>
  <ShippingServiceCost currencyID="CurrencyCodeType">44.99</ShippingServiceCost>
  <ShippingServicePriority>2</ShippingServicePriority>
<ShipToLocation>BE</ShipToLocation><ShipToLocation>FR</ShipToLocation><ShipToLocation>IE</ShipToLocation><ShipToLocation>LU</ShipToLocation><ShipToLocation>MC</ShipToLocation><ShipToLocation>NL</ShipToLocation><ShipToLocation>GB</ShipToLocation><ShipToLocation>DE</ShipToLocation><ShipToLocation>IT</ShipToLocation></InternationalShippingServiceOption>

 

I am using the $doc->formatOutput = true; option.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.