는 XML 문서를 조작하려면하지만이 테스트하지 작동 것이라고 생각 (즉, 한 문서에서 다른 문서로 노드를 추가), 당신은 DOMDocum를 사용한다 단순한 XML이 아닌 ent입니다.
다음은 DOMDocument를 사용하여 한 문서에서 다른 문서로 복사하는 코드입니다. 이것은 두 단계 과정입니다. 먼저 노드를 $ ndTemp로 문서로 임포트하십시오. 둘째, 가져온 $ ndTemp을 지정된 부모에 추가합니다 (루트 documentElement 만 사용하지만 다른 노드 일 수 있음).
참고 : 단순한 사본을하고 있다면, ...
입력 XML (movie.xml)
<xml>
<movie name='first'>
<cast>
<person name="Nanda Anand" character="" job="Director" id="589088" thumb="" department="Directing" url="http://www.themoviedb.org/person/589088" order="0" cast_id="1000"/>
<person name="Lynn Collins" character="" job="Actor" id="21044" thumb="http://cf2.imgobject.com/t/p/w185/berS11tKvXqTFThUWAYrH279cvn.jpg" department="Actors" url="http://www.themoviedb.org/person/21044" order="0" cast_id="1001"/>
</cast>
</movie>
<movie name='Second'>
<cast>
<person name="Zaphod Beeblebrox" character="" job="Director" id="589088" thumb="" department="Directing" url="http://www.themoviedb.org/person/589088" order="0" cast_id="1000"/>
</cast>
</movie>
</xml>
PHP를 사용하면 XSL 사용을 고려할 수 있지만, 그것은 또 다른 포스트
<?php
$xml = new DOMDocument();
$strFileName = "movie.xml";
$xml->load($strFileName);
$xmlCopy = new DOMDocument();
$xmlCopy->loadXML("<xml/>");
$xpath = new domxpath($xml);
$strXPath = "/xml/movie/cast/person";
$elements = $xpath->query($strXPath, $xml);
foreach($elements as $element) {
$ndTemp = $xmlCopy->importNode($element, true);
$xmlCopy->documentElement->appendChild($ndTemp);
}
echo $xmlCopy->saveXML();
?>
출력
<?xml version="1.0"?>
<xml>
<person name="Nanda Anand" character="" job="Director" id="589088" thumb="" department="Directing" url="http://www.themoviedb.org/person/589088" order="0" cast_id="1000" />
<person name="Lynn Collins" character="" job="Actor" id="21044" thumb="http://cf2.imgobject.com/t/p/w185/berS11tKvXqTFThUWAYrH279cvn.jpg" department="Actors"
url="http://www.themoviedb.org/person/21044" order="0" cast_id="1001" />
<person name="Zaphod Beeblebrox" character="" job="Director" id="589088" thumb="" department="Directing" url="http://www.themoviedb.org/person/589088" order="0" cast_id="1000" />
</xml>
"그것은 아무튼 '일'은 당신이 줄 수있는 가장 쓸모없는 정보에 관한 것입니다. 작동하지 않는 것은 무엇입니까? 작동하지 않는다는 것을 어떻게 알 수 있습니까? 오류 메시지가 나타 납니까? – hoppa
죄송합니다. 제 말은 구조에서 발견되는 사람마다 을 복사하는 것입니다. 속성을 복사해야합니다. 지금 도와 주실 수 있습니까? –
Max
나쁘다. 그냥 내 편이라는 말을 듣기 만하면된다. 우리는 서로를 돕기 위해 여기에 있다고 생각해야합니다. – Max