2011-12-21 3 views
0

한 영화의 데이터가 포함 된 XML이 여러 개 있으며 모든 영화와 함께 하나의 XML을 만들고 싶습니다. 어떻게해야합니까? 나는이 같은 XML 뭔가가 필요XML 노드를 XML 노드 컬렉션에 복사 (PHP)

<movie> 
<popularity>0.018</popularity> 
<translated>true</translated> 
<adult>false</adult> 
<language>en</language> 
<original_name>Return to Rajapur</original_name> 
<name>Return to Rajapur</name> 
<alternative_name>Retorno a Rajapur</alternative_name> 
<type>movie</type> 
<id>80261</id> 
<imdb_id>tt0444415</imdb_id> 
<url>http://www.themoviedb.org/movie/80261</url> 
<overview> 
A doomed love affair blooms against the beautiful and exotic backdrop of the deserts of India in this romantic drama. Samantha Hartley (Kelli Garner) is a woman in her early twenties who travels to Rajapur in India to visit a resort where her mother stayed years ago. While tracing the steps of her mother, Sara (Lynn Collins), Samantha learns the true story about her mother's stormy marriage to Jeremy (Justin Theroux), a charming but moody alcoholic. Only a few days after their wedding, Sara began to wonder if marrying Jeremy was a mistake, and while visiting India on their honeymoon, Sara met Jai Singh (Manoj Bajpai), a handsome and sensitive widower living in Rajapur. Jai Singh, who speaks fluent English, soon strikes up a friendship with Sara that quickly grows into a romance, but both are aware of the transgressive nature of their love, and their affair takes a tragic turn, leaving its scars on all parties involved. 
</overview> 
<votes>0</votes> 
<rating>0.0</rating> 
<tagline/> 
<certification/> 
<released>2006-11-01</released> 
<runtime>97</runtime> 
<budget/> 
<revenue/> 
<homepage/> 
<trailer>http://www.youtube.com/watch?v=b2bc8dHUco4</trailer> 
<categories></categories> 
<keywords></keywords> 
<studios></studios> 
<languages_spoken> 
<language_spoken code="en" name="English" native_name="English"/> 
<language_spoken code="hi" name="Hindi" native_name=""/> 
</languages_spoken> 
<countries></countries> 
<images> 
<image type="poster" url="http://cf2.imgobject.com/t/p/w92/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="thumb" width="92" height="136" id="4ee0cac57b9aa14e0f00272e"/> 
<image type="poster" url="http://cf2.imgobject.com/t/p/w154/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="w154" width="154" height="228" id="4ee0cac57b9aa14e0f00272e"/> 
<image type="poster" url="http://cf2.imgobject.com/t/p/w185/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="cover" width="185" height="274" id="4ee0cac57b9aa14e0f00272e"/> 
<image type="poster" url="http://cf2.imgobject.com/t/p/w342/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="w342" width="342" height="507" id="4ee0cac57b9aa14e0f00272e"/> 
<image type="poster" url="http://cf2.imgobject.com/t/p/w500/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="mid" width="500" height="741" id="4ee0cac57b9aa14e0f00272e"/> 
<image type="poster" url="http://cf2.imgobject.com/t/p/original/tPuPbPCg0cAwWAAasVAyy4366BA.jpg" size="original" width="1120" height="1660" id="4ee0cac57b9aa14e0f00272e"/> 
</images> 
<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"/> 
<person name="Kelli Garner" character="" job="Actor" id="17442" thumb="http://cf2.imgobject.com/t/p/w185/tV4nlT3ApNd2iQMN2JGr6uCnoxX.jpg" department="Actors" url="http://www.themoviedb.org/person/17442" order="1" cast_id="1002"/> 
<person name="Justin Theroux" character="" job="Actor" id="15009" thumb="http://cf2.imgobject.com/t/p/w185/hkJ8UaqMacoIiVkqu1AG69cIjMI.jpg" department="Actors" url="http://www.themoviedb.org/person/15009" order="2" cast_id="1003"/> 
</cast> 
<version>1</version> 
<last_modified_at>2011-12-21 11:18:06 UTC</last_modified_at> 
</movie> 

:

그것은 영화 XML의 예입니다

<movies> 
<movie> 
</movie> 
</movies> 

내가 그것을 할 수있는 방법이 확신을하지만 PHP와 XML에 대해 새로운 것이므로 도움이 필요합니다! 덕분에 !

답변

1

이 매우 우아한 해결책은 아니지만 작업 할 수없는 XML이없는 * 경우

<?php 
$files = array("file1.xml","file2.xml","file3.xml"); 
$output = fopen("result.xml","w"); 
fwrite($output,"<movies>"); 
foreach ($files as $f) 
{ 
    fwrite($output,file_get_contents($f)); 
} 
fwrite($output,"</movies>"); 
?> 
+1

이 완벽하게 좋은 솔루션 *는 다음과 같습니다 각 파일을 읽고 하나 개의 파일에 콘텐츠를 넣을 수 있습니다 파일에 프롤로그 – Gordon