我在XML中使用實體,我不理解我的結果。不理解XML實體和PHP中的輸出SimpleXMLElement
我有一個XML文件至極調用外部實體,這是config.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE config [
<!ENTITY totalInstances SYSTEM "totalInstances.xml">
]>
<config>
&totalInstances;
</config>
這裏是文件totalInstances.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<totalInstances>
<nombre>45</nombre>
</totalInstances>
在PHP
所以我加載文件config.xml在類SimpleXMLElement的幫助下:
$config = simplexml_load_file('config.xml');
然後我輸出變量$ config with av ar_dump,這裏是我不明白的事情:
object(SimpleXMLElement)[3]
public 'totalInstances' =>
object(SimpleXMLElement)[5]
public 'totalInstances' =>
object(SimpleXMLElement)[6]
public 'totalInstances' =>
object(SimpleXMLElement)[8]
public 'nombre' => string '45' (length=2)
我希望有一個簡單的「totalInstances」節點包含節點「農佈雷」。 會發生什麼? 謝謝。
編輯:有關更多詳細信息,我不明白爲什麼我會在文件totalInstances.xml中只有一個名爲「totalInstances」的三個對象?我希望有這樣的輸出:
object(SimpleXMLElement)[3]
public 'totalInstances' =>
object(SimpleXMLElement)[8]
public 'nombre' => string '45' (length=2)
而且,我不知道明白什麼意思的「[]」之間的數輸出。
它是什麼你不明白嗎?我只能在那裏看到一個應該正確的'nombre'節點? – silkfire 2013-04-20 11:11:07
@silkfire,我認爲OP不明白爲什麼有3個'totalInstances'(SimpleXML)元素,因爲他只在其XML文檔中定義了一個元素... – Havelock 2013-04-20 11:15:52