PHP curlを使用してリモートURLからxmlファイルを取得し、サーバー上のローカルファイルに保存しています。構造は次のとおりです。
<Store Country="Ireland">
<EventsPoints>
<Event ID="1800" >
<ArtistIDs>
<ArtistID ID="109" Type="Primary" />
</ArtistIDs>
<CategoryID>1</CategoryID>
<Country>IRL</Country>
<PerformanceName>Music and Arts</PerformanceName>
<VenueID ID="197" />
</Event>
<Venues>
<Venue ID="197">
<City>Dublin</City>
<Country>IRL</Country>
<VenueName>ABC</VenueName>
<VenueNumber>22</VenueNumber>
</Venue>
</Venues>
上記のxmlブロックは同じXMLファイルに保存されます。いくつかのイベントブロックといくつかの会場ブロックがあります。私が抱えている問題は、PHPを使用してこの大きなXMLファイルにアクセスし、Venueブロックを反復処理して、パラメーターで指定された特定のIDを持つVenueブロックのみを取得することです。次に、イベントブロックを反復処理します。この指定された会場IDに一致するイベントのみを取得します。次に、これをサーバー上のファイルに保存します。会場ごとにやりたいです。
上記を行うにはどうすればよいですか?
編集:
各会場とその会場に関連するイベントについて、私はそれらを文字通り独自のファイルにコピーしたいだけです-基本的に大きなファイルを個々のファイルに分割します
$docSource = new DOMDocument();
$docSource->loadXML($xml);
$docDest = new DOMDocument();
$docDest->loadXML(file_get_contents('/var/www/html/xml/testfile.xml'));
$xpath = new DOMXPath($docSource);
$id = "197";
$result = $xpath->query('//Event/VenueID[@ID=$id]')->item(0); //Get directly the node you want
$result = $docDest->importNode($result, true); //Copy the node to the other document
$items = $docDest->getElementsByTagName('items')->item(0);
$items->appendChild($result); //Add the copied node to the destination document
echo $docDest->saveXML();