2015-02-10 262 views
-3

我需要將多個xml文件合併爲一個xml文件。我認爲這很容易,但我無法弄清楚。有沒有這個工具(OSX)或我必須使用腳本?所有的xml文件都是這樣的。有沒有辦法將這些與php結合成一個文件?將多個xml文件合併爲單個xml文件

<?xml version="1.0"?> 
 
<trcitem xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" availablefrom="2015-02-01T00:00:00" availableto="2015-02-08T00:00:00" trcid="2b7fde5b-56d7-4dc2-9b37-d8e5baa72ff3" createdby="[email protected]" creationdate="2015-02-01T13:23:57" lastupdated="2015-02-08T00:52:01" lastupdatedby="[email protected]" owner="VVV Altena Biesbosch Invoerders" wfstatus="approved" published="false" legalowner="[email protected]" lastimportedon="2015-02-01T13:23:58.023" deleted="false" offline="false" xmlns="http://www.vvvnederland.nl/XMLSchema/TrcXml/2.0"> 
 
    <calendar excludeholidays="false"> 
 
    <single date="07/02/2015"> 
 
     <when timestart="19:00:00" /> 
 
    </single> 
 
    </calendar> 
 
    <trcitemcategories> 
 
    <types> 
 
     <type catid="2.6.9">Gezelschap/orkest</type> 
 
    </types> 
 
    <soldout>false</soldout> 
 
    <canceled>false</canceled> 
 
    </trcitemcategories> 
 
    <media> 
 
    <file trcid="c4630ca2-ddef-41b7-a8f3-788cf59133d7" main="true"> 
 
     <filename>da599797-a9a1-4620-80c8-592657d4e97f.jpg</filename> 
 
     <filetype>jpg</filetype> 
 
     <hlink>http://media.ndtrc.nl/Images/20150201/da599797-a9a1-4620-80c8-592657d4e97f.jpg</hlink> 
 
     <mediatype>photo</mediatype> 
 
    </file> 
 
    </media> 
 
    <trcitemdetails> 
 
    <trcitemdetail lang="de"> 
 
     <calendarsummary>Samstag 7 Februar 2015, 19:00 Uhr.</calendarsummary> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    <trcitemdetail lang="en"> 
 
     <calendarsummary>Saturday 7 February 2015, 19:00 hour.</calendarsummary> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    <trcitemdetail lang="fr"> 
 
     <calendarsummary>Samedi 7 Février 2015, 19:00 heure.</calendarsummary> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    <trcitemdetail lang="nl"> 
 
     <calendarsummary>Zaterdag 7 februari 2015, 19:00 uur.</calendarsummary> 
 
     <longdescription>&lt;p style="font-family: arial; font-size: 12px; line-height: 16px;"&gt;De Jeugdmuziekdag Altena wordt gehouden op 7 februari 2015 in &amp;rsquo;t Verlaat in Almkerk. Tijdens deze dag speel je samen met andere muzikanten in &amp;eacute;&amp;eacute;n groot orkest en wordt er gewerkt aan een concertprogramma onder leiding van professionele dirigenten. Het thema is &amp;ldquo;Movies Music&amp;rdquo;.&lt;br /&gt; 
 
&lt;br /&gt; 
 
Elkemuzikant tot 21 jaar uit het Land van Heusden en Altena die een muziekinstrument bespeelt dat voorkomt in een HaFaBra-orkest, is welkom. Je hoeft niet per se lid te zijn van een muziekvereniging.&lt;br /&gt; 
 
&lt;br /&gt; 
 
De opgaveatum sloot op 24-12-2014&lt;/p&gt; 
 
&lt;p style="font-family: arial; font-size: 12px; line-height: 16px;"&gt;Het slotconcert begint om 19:00 uur en daarvoor is de entree gratis.&lt;/p&gt;</longdescription> 
 
     <shortdescription>één groot orkest </shortdescription> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    <trcitemdetail lang="it"> 
 
     <calendarsummary>Sabato 7 febbraio 2015, 19:00 Ora.</calendarsummary> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    <trcitemdetail lang="es"> 
 
     <calendarsummary>Sábado 7 Febrero 2015, 19:00 Hora.</calendarsummary> 
 
     <title>Jeugdmuziekdag Altena</title> 
 
    </trcitemdetail> 
 
    </trcitemdetails> 
 
    <location> 
 
    <address> 
 
     <physical giscoordinateType="points"> 
 
     <city>ALMKERK</city> 
 
     <country>NL</country> 
 
     <housenr>1</housenr> 
 
     <street>'t Verlaat </street> 
 
     <zipcode>4286</zipcode> 
 
     <giscoordinates> 
 
      <giscoordinate> 
 
      <xcoordinate>4,957688</xcoordinate> 
 
      <ycoordinate>51,769918</ycoordinate> 
 
      </giscoordinate> 
 
     </giscoordinates> 
 
     <xcoordinate>4,957688</xcoordinate> 
 
     <ycoordinate>51,769918</ycoordinate> 
 
     </physical> 
 
    </address> 
 
    <actor availablefrom="2015-02-01T13:23:57" createdby="[email protected]" creationdate="2015-02-01T13:23:57" trcid="13862988-5229-45a3-8500-214421ed1a02" lastupdated="2015-02-01T13:23:57" lastupdatedby="[email protected]" owner="Systeembeheerders"> 
 
     <actordetails> 
 
     <actordetail lang="nl"> 
 
      <title>'t Verlaat</title> 
 
     </actordetail> 
 
     </actordetails> 
 
     <contactinfo> 
 
     <address> 
 
      <physical> 
 
      <city>ALMKERK</city> 
 
      <country>NL</country> 
 
      <housenr>1</housenr> 
 
      <street>'t Verlaat </street> 
 
      <zipcode>4286</zipcode> 
 
      <giscoordinates> 
 
       <giscoordinate> 
 
       <xcoordinate>4,957688</xcoordinate> 
 
       <ycoordinate>51,769918</ycoordinate> 
 
       <label>'t Verlaat 1, 4286 ALMKERK, NL</label> 
 
       </giscoordinate> 
 
      </giscoordinates> 
 
      </physical> 
 
     </address> 
 
     </contactinfo> 
 
    </actor> 
 
    </location> 
 
    <userorganisation>VVV Altena Biesbosch</userorganisation> 
 
</trcitem>

+0

如果您想要一個有效的答案,您將需要添加更多細節。你目前有什麼代碼?什麼平臺,你在用什麼語言?源xml的外觀如何?組合的xml應該如何查看? – 2015-02-10 20:53:17

+0

Soryy如果它不清楚的問題。 Thougt很簡單。我有一個zip文件,裏面有很多xml文件。這些文件代表事件。而不是導入所有這些單個XML文件。我想將它們合併到一個文件並導入。 – Toasty 2015-02-10 22:19:33

+1

那麼,平臺/操作系統呢?你想使用的編程語言怎麼樣?試圖提供答案時,這些事情很重要! – 2015-02-10 22:28:20

回答

0

假設每個單獨的XML文件都中規中矩,你可以打開一個新的文件,添加一個XML聲明(可選),創建一個新的手動或編程將它們組合根元素(必需),並將每個XML文件的根元素添加到新的組合XML文件的根元素。

<?xml version="1.0" encoding="UTF-8"?> 
<root> 
    <File1Root>...</File1Root> 
    <File2Root>...</File2Root> 
    <File3Root>...</File3Root> 
</root> 

注:

  • 新的XML文件必須有一個根元素,否則它不能很好地形成。
  • 注意不要在 新XML文件中包含多於一個XML聲明。
  • 您可能需要調整名稱空間聲明以確保新XML文件中的一致性。
+0

Thanx。有沒有辦法使這個過程自動化?有超過100個數字名稱的文件。 – Toasty 2015-02-10 22:21:56

+0

當然,你還沒有告訴我們你想用什麼編程語言。 – kjhughes 2015-02-11 00:56:08

+0

對不起。我主要使用PHP,但我是一個新手。 – Toasty 2015-02-11 09:29:08