這裏是我的XML:PHP DOM奇數輸出?
<?xml version="1.0" encoding="UTF-8"?>
<columns>
<column>
<originalName>ORP</originalName>
<name>ORP</name>
<visible>1</visible>
</column>
<column>
<originalName>OKRES</originalName>
<name>OKRES</name>
<visible>1</visible>
</column>
<column>
<originalName>Objekt</originalName>
<name>Objekt</name>
<visible>1</visible>
</column>
<column>
<originalName>Školenie</originalName>
<name>Skolenie</name>
<visible>1</visible>
</column>
<column>
<originalName>Dátum posledného školenia OPP</originalName>
<name>DatumPoslednehoSkoleniaOPP</name>
<visible>1</visible>
</column>
<column>
<originalName>Dátum posledného školenia OPP</originalName>
<name>DatumPoslednehoSkoleniaOPP1</name>
<visible>0</visible>
</column>
</columns>
我的代碼遍歷所有列:
$schema = new DOMDocument();
$schema->load(BASE_PATH.'/schema.xml');
foreach ($schema->getElementsByTagName('column') as $column) {
foreach($column->childNodes as $child) {
echo $child->nodeName, ' => ', $child->nodeValue, '<br />';
}
}
現在輸出是最奇怪的。我不明白爲什麼「#text =>」繼續出現有:
#text =>
originalName => ORP
#text =>
name => ORP
#text =>
visible => 1
#text =>
#text =>
originalName => OKRES
#text =>
name => OKRES
#text =>
visible => 1
#text =>
#text =>
originalName => Objekt
#text =>
name => Objekt
#text =>
visible => 1
#text =>
#text =>
originalName => Školenie
#text =>
name => Skolenie
#text =>
visible => 1
#text =>
#text =>
originalName => Dátum posledného školenia OPP
#text =>
name => DatumPoslednehoSkoleniaOPP
#text =>
visible => 1
#text =>
#text =>
originalName => Dátum posledného školenia OPP
#text =>
name => DatumPoslednehoSkoleniaOPP1
#text =>
visible => 0
#text =>
看看我的架構,不存在 '#text' 元素有任何責任。它不應該打印。 – 2011-01-27 08:58:19
試試這個print_r($ child); (DOMText Object()originalName => ORP),(DOMElement Object()#text =>) – FeRtoll 2011-01-27 09:01:22