这是我工作的xml输出
<adamContent projectTypeID="10" genContentID="000002">
<metaData>
<keywordList>
<keyword>
<word>#27</word>
<relevancy>120</relevancy>
</keyword>
<keyword>
<word>#43</word>
<relevancy>114</relevancy>
</keyword>
</keywordList>
<taxonomy type="CPT">
<code>99374</code>
</taxonomy>
</metaData>
<textContent title="Description" ordinal="0" group="0">
<p>An in-depth report on the causes, diagnosis, and treatment of Alzheimer's disease.</p>
</textContent>
</adamContent>
我需要输出(我想删除整个元数据节点)
<adamContent projectTypeID="10" genContentID="000002">
<textContent title="Description" ordinal="0" group="0">
<p>An in-depth report on the causes, diagnosis, and treatment of Alzheimer's disease.</p>
</textContent>
</adamContent>
这是我到目前为止尝试的PHP代码
<?php
$xmldoc = new DOMDocument();
$atvID = $xmldoc->load('000002.xml', LIBXML_NOBLANKS);
foreach($atvID as $id){
$delnode = $xmldoc->getElementsByTagName('metaData');
$xmldoc->firstChild->removeChild($delnode->item($id));
}
$xmldoc->save('000002.xml');
?>
答案 0 :(得分:3)
$xmldoc = new DOMDocument();
$xmldoc->load('000002.xml');
$metadatas = $xmldoc->getElementsByTagName('metaData');
foreach ($metadatas as $metadata) {
$metadata->parentNode->removeChild($metadata);
}
$xmldoc->save('000002.xml');