2016-07-01 13 views
0

2つのXMLファイルがありますが、両方のXMLファイルのエントリを置き換えたり置き換えたりしたいと思います。1つのxmlファイルのタグを別のXMLファイルに置き換えたり置換したりする

たとえば、以下のようにtest1.xmlには、name = ""という唯一のものがリストされ、他のタグは空です。私はその後、年を除くすべてのtest2.xmlを持っているので、タグの隙間を埋めるか、コマンドライン(バッチ)またはPHPを使って情報を置き換えたいと思います。

test1.xml

<game name="test1" image=""> 
    <description>test1</description> 
    <manufacturer></manufacturer> 
    <year></year> 
    <genre>1985</genre> 
    <rating></rating> 
</game> 
    <game name="test2" image=""> 
    <description>test2</description> 
    <manufacturer></manufacturer> 
    <year>1984</year> 
    <genre></genre> 
    <rating></rating> 
</game> 
    <game name="test3" image=""> 
    <description>test3</description> 
    <manufacturer></manufacturer> 
    <year>1986</year> 
    <genre></genre> 
    <rating></rating> 
</game> 

test2.xml

<game name="test1" index="true" image=""> 
    <description>test1</description> 
    <manufacturer>Activision</manufacturer> 
    <year></year> 
    <genre>Olympic/Sports</genre> 
    <rating>HSRS - GA (General Audience)</rating> 
</game> 
<game name="test2" index="" image=""> 
    <description>test2</description> 
    <manufacturer>Parker Brothers</manufacturer> 
    <year></year> 
    <genre>Action</genre> 
    <rating>HSRS - GA (General Audience)</rating> 
</game> 
<game name="test3" index="true" image=""> 
    <description>test3</description> 
    <manufacturer>Atari</manufacturer> 
    <year></year> 
    <genre>Sports</genre> 
    <rating>HSRS - GA (General Audience)</rating> 
</game> 

私は、次のコードreplace/substitute a tag value from one xml file to another xml using phpを見ていたし、それが動作するようになったが、それは、複数のタグから全ての情報を保持しません。その後、すべてのタグに最初のentriesタグを使用して、100個のエントリがあるとします。置き換えると、すべてのタグがすべての個別情報を保持しない同じ情報に置き換えられます。

答えて

0

より良いアプローチは、xsltを使用することです。選択ノードの内容をtest1からコピーします。

乾杯!

関連する問題