Hello all,
My name Rithy.
I don't know how to add new line before appending a new node or element in the xml.
My php:
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = true;
$dom->load($xml_file);
$body = $dom->getElementsByTagName('body')->item(0);
$newelement_seg = $dom->createElement('seg');
$data = $dom->createTextNode(" text 2 ");
$newelement_seg->appendChild($data);
$body->appendChild($newelement_seg);
$dom->save($xml_file);
XML Before append a new child:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg>
</body>
</xml>
XML after append a new child:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg><seg> text 2 </seg></body>
</xml>
But I want:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<seg>
text 1
</seg>
<seg>
text 2
</seg>
</body>
</xml>
Thanks in advanced!