DOMDocument를 사용하여 XML 파일을 구문 분석하고 있습니다. 다른 요소를 반복하고 그 중 하나가 누락되어 있는지 확인하고 오류 메시지와 함께 createElement 배열을 채 웁니다. 마지막에 그 배열에 appendChild하기 위해 노력하고있어하지만 난 항상 같은 오류 메시지가 :PHP : DOMNode :: appendChild를 배열로 배열
Uncaught exception 'DOMException' with message 'Wrong Document Error'
DOMNode->appendChild(Object(DOMElement))
1 {main}
thrown in /xxx/xxx.php on line 235
PHP Fatal error: Call to undefined method DOMElement::item() in /xxx/xxx.php on line 235.
코드는 다음과 같다 :
$SMQuery = new DOMDocument();
$SMQuery->loadXML($params);
$response = $SMQuery->createElement('SMreply');
$errors = array();
if (!$reqtyp = $SMQuery->getElementsByTagName("tag1"))
{$errors[] = $SMQuery->createElement('error', 'tag1 Element is missing');}
if (!$reqtyp = $SMQuery->getElementsByTagName("tag2"))
{$errors[] = $SMQuery->createElement('error', 'tag2 Element is missing');}
......
if(!empty($errors))
{
foreach($errors as $error) {
$response->appendChild($error); <==== this line is causing the error !!!
}
}
어떤 도움을 많이 감사합니다. 건배, Riki.
GOT IT !!!! 원래 코드에 오타가있었습니다! –
오타 및 수정은 무엇입니까? –