我在嘗試以下但未成功。任何人誰可以幫我解釋爲什麼屬性imageId沒有改變?更新XML節點屬性
$dom = new DOMDocument;
$dom->loadXML($appCom_file_name);
$frames = $dom->getElementsByTagName('frame');
foreach ($frames as $frame) {
if ($frame->getAttribute('imageId') == '') {
$frame->setAttribute('imageId', $id);
}
}
$dom->saveXML();
XML源:
<template>
<appCom>
<page>
<defaultValues>
<frame id="frame_01_0" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
<frame id="frame_02_0" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
<frame id="frame_03_0" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
</defaultValues>
</page>
<page>
<defaultValues>
<frame id="frame_01_1" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
<frame id="frame_02_1" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
<frame id="frame_03_1" deltaRotation="0" deltaScale="100" deltaX="0" deltaY="0" imageId="" />
</defaultValues>
</page>
</appCom>
</template>
嘗試用引用的foreach'的foreach($幀作爲&$幀)' – Justinas 2014-12-02 11:01:42
感謝@Justinas您的快速反應,但它並沒有幫助。任何其他想法? – 2014-12-02 11:07:55
當你打印出'if'裏面的東西時,它會顯示出來嗎? – Justinas 2014-12-02 11:13:26