
moveToElement 메서드는 XMLReader 객체가 현재 위치를 지정된 요소에 맞춰 이동시키는 메서드입니다. 이 메서드는 XML 문서의 현재 위치를 지정된 요소에 맞춰 이동시키기 때문에, moveToElement 메서드를 호출한 후에는 getCurrentNode() 메서드를 사용하여 현재 위치에 있는 노드를 참조할 수 있습니다.
moveToElement 메서드를 호출하는 예제는 다음과 같습니다.
#hostingforum.kr
php
$xmlReader = new XMLReader();
$xmlReader->open('example.xml');
$xmlReader->read();
$xmlReader->moveToElement($xmlReader, '/root/child');
$currentNode = $xmlReader->getCurrentNode();
echo $currentNode->name; // 'child'
echo $currentNode->textContent; // 'child content'
위의 예제에서, `moveToElement` 메서드는 XMLReader 객체가 현재 위치를 `/root/child` 요소에 맞춰 이동시킵니다. 그 후, `getCurrentNode` 메서드를 사용하여 현재 위치에 있는 노드를 참조할 수 있습니다.
2025-06-19 16:50