$xml = new DOMDocument();
$xml_store_inventory = $xml->createElement('store-inventory'); // highest layer
$xml_item = $xml->createElement('item');
$xml_quantity = $xml->createElement('quantity');
$xml->appendChild($xml_store_inventory);
$xml_store_inventory->appendChild($xml_item);
$xml_location->appendChild($xml_quantity);
填充值給出:PHP DOM:在XML數據
<?xml version="1.0"?>
<store-inventory>
<item>
<quantity></quantity>
</item>
</store-inventory>
所以,我設法使用DOM創建以上PHP。我一直在網上搜索如何「填充」,但我沒有找到任何有關如何做到這一點的信息。
更具體地說,我想這是這個樣子
<?xml version="1.0" encoding="UTF-8"?>
<store-inventory
xmlns="http://..."
xmlns:xsi="http://..."
xsi:schemaLocation="http://...">
<item item-id="abcd">
<quantity>0</quantity>
</item>
</store-inventory>
所以,我想添加/更改如下:
- 改變XML版本線包括編碼(颳了這個,我想出了 - > $ xml = new DOMDocument('1.0','UTF-8');)
- 向元素添加額外的信息。例如[項目] [項目項目-ID = 「ABCD」]
- 同樣[數量]到[量] 0 /數量]
有人可以幫助我? TIA!
嗯,我只是注意到了。在對我以前的帖子進行一些訪問之後,看起來它是爲我的帖子標記解決方案。我不這樣做。對不起,我有點新。 – musicliftsme
沒問題,只是有點提醒;)。我在你的問題中不理解:「1.將XML版本行更改爲包含編碼」我都在XML中看到版本和編碼。你想改變什麼? – hakre
@hakre,上面的第三塊代碼就是我希望XML看起來像的樣子。我更新了我的帖子,以便反映出我已經找到了1.現在我需要弄清楚2和3! – musicliftsme