我有这个XML:
<photo>
<position>1</position>
<title>panos1</title>
</photo>
<photo>
<position>2</position>
<title>panos2</title>
</photo>
<photo>
<position>3</position>
<title>panos3</title>
</photo>
<photo>
<position>4</position>
<title>panos4</title>
</photo>
我想使用PHP删除值position
的{{1}}标记。
我正在使用4
答案 0 :(得分:0)
您可以使用removeChild()。 看看这个:
<?php
$xml = new DOMDocument();
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->loadXML($str) or die("Error");
// original
echo "<xmp>OLD:\n". $xml->saveXML() ."</xmp>";
// get document element
$root = $xml->documentElement;
$fnode = $root->firstChild;
//get a node
$ori = $fnode->childNodes->item(1);
// remove
$fnode->removeChild($ori);
echo "<xmp>NEW:\n". $xml->saveXML() ."</xmp>";
?>