1
DOM 및 PHP를 사용하여 XML 문서 내에서 자식 노드를 삭제하려고하는데 어떻게해야할지 잘 모르겠습니다. 나는 simpleXML에 접근 할 수 없다.DOM 및 PHP를 사용하여 XML 파일의 자식 노드 제거
XML 레이아웃 :
<list>
<as>
<a>
<a1>delete</a1>
</a>
<a>
<a1>keep</a1>
</a>
</as>
<list>
PHP 코드 :
$xml = "file.xml";
$dom = DOMDocument::load($xml);
$list = $dom->getElementsByTagName('as')->item(0);
//Cycle through <as> elements (there are multiple in the full file)
foreach($list->childNodes as $child) {
$subChild = substr($child->tagName, 0, -1);
$a = $dom->getElementsByTagName($subChild);
//Cycle through <a> elements
foreach($a as $node)
{
//Get status for status check
$check= $node->getElementsByTagName("a1")->item(0)->nodeValue;
if(strcmp($check,'delete')==0)
{
//code to delete here (I wish to delete the <a> that this triggers
}
}
}