
December 6th, 2006, 01:19 PM
|
|
Contributing User
|
|
Join Date: Apr 2007
Location: Hyderabad, AP, India
Posts: 49
Time spent in forums: 3 h 55 m 43 sec
Reputation Power: 3
|
|
|
Debug Code on XML
Hi all,
I have a small xml file of the following format.
php Code:
Original
- php Code |
|
|
|
<?xml version="1.0" encoding="ISO-8859-1"?> <contacts> </contacts>
and my source code to insert a tag is
php Code:
Original
- php Code |
|
|
|
function write2xml($flname,$entry,$vname,$vsip,$vNumber) { $dom = new DOMDocument(); $dom->load($flname); $dom->formatOutput = 1; $quote = $dom->createElement('entry'); $quote->setAttribute('uri', "sip:kumar@company.org"); $name = $dom->createElement('name'); $nameText = $dom->createTextNode($vname); $name->appendChild($nameText); $sip = $dom->createElement('sip'); $sipText = $dom->createTextNode($vsip); $sip->appendChild($sipText); $number = $dom->createElement('Number'); $numberText = $dom->createTextNode($vNumber); $number->appendChild($numberText); $quote->appendChild($name); $quote->appendChild($sip); $quote->appendChild($number); $dom->documentElement->appendChild($quote); $dom->save($flname); } write2xml("test.xml","sip:kumar@company.org","kumar","sip:kumar@company.org","9441788706");
When I execute this code the insertion takes place properly but all nodes are appended on the same line. (Please note: we see same line only when opened in notepad or any text editor and not in browsers)
<entry uri="sip:kumar@company.org"><name>kumar</name><sip>sip:kumar@company.org</sip><Number>9441788706</Number></entry>
While I desire a line break between tags when opened in any text editors in the following format.
<entry uri="sip:kumar@company.org">
<name>kumar</name>
<sip>sip:kumar@company.org</sip>
<Number>9441788706</Number>
</entry>
How do I insert the line break in my code.
Thanx in advance for any help.
Regards,
tvks
|