- 我怎樣才能將標籤xml
<newWord>
正確的地方寫下來?和標籤<Heb>
我的代碼重寫XML文件中,當他加入他的數據添加到第一線的所有,他從爵士得到的數據和該行之前會很長到很大。我怎樣才能在標籤xml之前和之後
我的代碼:
<?php
$wordH=$_GET['varHeb'];
$wordE=$_GET['varEng'];
$new_line = "\n";
$doc='';
if(!$doc)
{
$doc = new DOMDocument();
// we want a nice output
$doc->formatOutput = true;
$doc->load('Dictionary_user.xml');
}
$Dictionary_user = $doc->documentElement;
$newWord = $doc->createElement('newWord');
CHARSET=windows-1255"');
$prop = $doc->createElement('Heb', $wordH);
$newWord->appendChild($prop);
$prop = $doc->createElement('Eng',$wordE);
$newWord->appendChild($prop);
$Dictionary_user->childNodes->item(0)->parentNode->insertBefore($newWord,$Dictionary_user->childNodes->item(0));
header("Content-type: text/xml");
$doc->save("Dictionary_user.xml");
echo $doc->saveXML();
?>
壞resualt是:
<?xml version="1.0" encoding="UTF-8"?>
<Favorite_Word xml:lang="EN"><newWord><Heb>test1</Heb><Eng>test2</Eng></newWord><newWord><Heb>test1</Heb><Eng>test2</Eng></newWord><newWord><Heb>test1</Heb><Eng>test2</Eng></newWord>
test1test2`
<newWord>
<Heb>cow</Heb>
<Eng>Co</Eng>
</newWord>
<newWord>
<Heb>Camel</Heb>
<Eng>Ca</Eng>
</newWord>
<newWord>
<Heb>Bull</Heb>
<Eng>BUl</Eng>
</newWord>
好resualt是:
<Favorite_Word xml:lang="EN">
<newWord>
<Heb>test1</Heb>
<Eng>test2</Eng>
</newWord>
<newWord>
<Heb>cow</Heb>
<Eng>Co</Eng>
</newWord>
<newWord>
<Heb>Camel</Heb>
<Eng>Ca</Eng>
</newWord>
<newWord>
<Heb>Bull</Heb>
<Eng>BUl</Eng>
</newWord>
請添加當前結果的示例和預期結果的示例。 – VolkerK 2012-02-15 08:33:45