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.

Archived

This topic is now archived and is closed to further replies.

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