【发布时间】:2014-04-08 17:00:33
【问题描述】:
我正在尝试将具有属性“Boolean”的给定 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?
【问题讨论】: