IDで要素を取得しようとしています。しかし、私は成功していません。以下が指定された ID の要素を見つけられないのはなぜですか?
テストケースを設定しました:
<?php
$m_oDom = new DOMDocument( '1.0', 'UTF-8' );
$m_oDom->formatOutput = true;
$m_oDom->preserveWhiteSpace = false;
$m_oDom->validateOnParse = true;
$strId = "abc";
$oElement = $m_oDom->createElement( 'div' );
$oAttribute = $oElement->setAttribute( 'id', $strId );
$oElement->setIdAttribute( 'id', false ); // tried also without this
$oElement->appendChild( $oAttribute );
// $oAttribute = $oElement->getAttributeNode( 'id' );
$b = $oAttribute->isId();
if( $b ) {
echo "true";
} else {
echo "false"; // says false
}
$oElement = $m_oDom->getElementById( $strId );
if( $oElement ) {
echo "element";
} else {
echo "false"; // says false
}
?>