2011-12-21 9 views
0

私は1つのムービーのデータを含むXMLをいくつか持っており、すべてのムービーで1つのXMLを作成したいと思います。XMLノードをXMLノードコレクションにコピーする(PHP)

それは映画のXMLの例です:

<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

これは非常にエレガントな解決策ではありませんが、それが動作することができます:あなたは、各ファイルを読み込み、一つのファイルにその内容を置くことができます。

<?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

これは完全に罰金ソリューションです*何のxmlがない*場合ファイルのプロローグ – Gordon

関連する問題