저는 PHP로 XML 조작을 시작했습니다. 나는 예상치 못한 것을 발견했습니다. 여기에 내가 테스트 입력으로 사용하고있어 XML이있다 :PHP DOM : 오히려 초보자 용 질문
<list>
<activity1> running </activity1>
<activity2> swimming </activity2>
<activity3> soccer </activity3>
</list>
를 자, 내가 기대 한 것이 PHP 코드 것 출력 'activity1에'
$xmldoc = new DOMDocument();
$xmldoc->load('file.xml');
//the line below would make $root the <list> node
$root = $xmldoc->firstChild;
//the line below would make $cnode the first child
//of the <list> node, which is <activity1>
$cnode = $root->firstChild;
//this should output 'activity1'
echo 'element name: ' . $cnode->nodeName;
대신,이 코드를 출력하는 #text. 나는 노드 이름을 인쇄하기 전에, 코드의 새로운 라인을 삽입하여 그것을 고칠 수 :
$cnode = $cnode->nextSibling;
지금, 나는이 인쇄 대신 'activity2에'에 'activity1에'를 인쇄하는 것을 기대했을 것이다. 무슨 일 이니?
나는 지금 무슨 일이 일어나고 있는지 잘 알고 있다고 생각합니다. 감사 –