开发者

Create XML Element at NEW Line

i have a following xml file.

<question id="1">2011-01-07 23:59:38</question>
<question id="2">2011-01-08 0:01:44</question>
<question id="3"></question>

i am adding new question element. however it keeps adding it in here:

<question id="1">2011-01-07 23:59:38</question>
<question id="2">2011-01-08 0:01:44</question>
<question id="3"></question><question id="4"></question>

Rather than that, i want the new element to be added to a new line like this:

<question id="1">2011-01-07 23:59:38</question>
<question id="2">2011-01-08 0:01:44</question>
<question id="3"></question>
<question id="4"></question>

How can i achieve this? Here is my adding new element part of my code:

$question2 = $xpath->query("/question[position()=last()]->value(0)");

$id2 = $question2->getAttribute('id');
$item2 = $dom->createElement("question");
$question2->parentNode->insertBefore($item2, $question2 ->nextSibling);
$item2->setAtt开发者_开发技巧ribute('id', $row['idquestions']); 

Thanks!


You'd have to first insert a new text object containing a newline, and then insert the new element object after that. Whitespace is significant in XML (though many/most uses of XML ignore it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜