0
我試圖設置所有元素的具有屬性「布爾」的給定XML文件的值爲True,我有一個地獄的時間計算如何做到這一點:將屬性的所有元素設置爲一個特定的值
$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->loadXML($sxe->asXML());
$xpath = new DOMXPath($dom);
foreach ($xpath->query('//*[@type="Boolean"]') as $node) {
// something to set the value of $node to the value of "True"
}
echo $dom->saveXML();
我已經試過:
$node->{0} = value; // does not actually replace values but doesn't error
$node[0] = value; // errors Cannot use object of type DOMElement as array
此外,如果任何人都知道,我怎麼能告訴DOM不輸出使用簡寫的XML?
不,我想設置元素的值。屬性僅用於查找要更改的元素。 – VikingBlooded
哦,那麼使用'$ node-> nodeValue = value' – JWiley
正確,謝謝先生。你有沒有機會知道如何告訴DOM輸出XML而不使用簡寫XML標籤? – VikingBlooded