我已经浏览了整个网络并尝试了不同的方法,试图实现我想要的,但一切都不起作用。所以我希望你们中的一些人能指出我正确的方向。
我有一个xml文件,其中包含多个具有相同"名称"属性。从一个孩子我需要属性" created_for_playlist"和" sort_on_playlist"而且来自另一个孩子的名字"名称"属性我需要" name"和#34;持续时间"。两个孩子都有不同的属性......
是否可以获取此信息并合并xml或将其直接写入数组中,甚至直接打印或回显?
这是我的xml:
<assets>
<asset name="Blanco fragment" unique_id="83609dd0-d22c-4217-afc6-64bccf742bee_shot" type="shot" media-type="9" vam_state="1" created_for_layer="5" blank_shot="1" visible="1" />
<asset name="Blanco fragment" unique_id="fd090636-fff1-4492-9e1d-2000ea96f1d7_shot" type="shot" media-type="9" vam_state="7" created_for_layer="1" blank_shot="1" visible="1" />
<asset name="Blanco fragment" unique_id="15298038-fce9-4a6d-9297-5ff3729ec0aa_shot" type="shot" media-type="9" vam_state="1" created_for_layer="2" blank_shot="1" visible="1" sort_on_normal="0" />
<asset name="Blanco fragment" unique_id="6bac7b34-83e0-46e5-8e9a-57542ee51914_shot" type="shot" media-type="9" vam_state="1" created_for_layer="3" blank_shot="1" visible="1" />
<asset name="Blanco fragment" unique_id="fb0c8b36-8d8e-4d28-83b8-0e1628de347a_shot" type="shot" media-type="9" vam_state="1" created_for_layer="4" blank_shot="1" visible="1" />
<asset name="programma" unique_id="8228566d-0204-49ea-9089-7a8de978447c_shot" type="playlist_shot" media-type="9" vam_state="14" created_for_layer="2" visible="1" sort_on_normal="1" />
<asset name="Gat van Bolmers heet nu Kloosterplaats (Start project _Stadspark_).mp4" url="D:\wirecast\popuptv\video\201504\Gat van Bolmers heet nu Kloosterplaats (Start project _Stadspark_).mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="5725e2a4-8d1d-4f35-879f-81e8e8ca720c_Gat van Bolmers heet nu Kloosterplaats (Start project _Stadspark_).mp4" timescale="90000" duration="77410800" square_pixel_width="1920" square_pixel_height="1080" visible="1" />
<asset name="Gat van Bolmers heet nu Kloosterplaats (Start project _Stadspark_).mp4" unique_id="7c8e3ce3-75b6-4691-9231-76e4ff20791b_shot" type="shot" media-type="9" veil_track_count="0" vam_state="8" video_tracks="1" still_image_tracks="0" alpha_track_count="1" audio_tracks="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" sort_on_playlist="0" visible="1" />
<asset name="Straatmuzikanten, de gebroeders Maarten en Arthur.mp4" url="D:\wirecast\popuptv\video\201504\Straatmuzikanten, de gebroeders Maarten en Arthur.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="b34202e0-9b57-405d-aed0-7f4bc72eb433_Straatmuzikanten, de gebroeders Maarten en Arthur.mp4" timescale="90000" duration="108514800" visible="1" square_pixel_height="1080" square_pixel_width="1920" />
<asset name="Straatmuzikanten, de gebroeders Maarten en Arthur.mp4" unique_id="bd3d0bbb-017b-4376-982e-d4fe54268b38_shot" type="shot" media-type="9" veil_track_count="0" sort_on_playlist="1" video_tracks="1" still_image_tracks="0" alpha_track_count="1" audio_tracks="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" vam_state="8" visible="1" />
<asset name="vlaardingGlorie2Letzso.mp4" url="D:\wirecast\popuptv\video\201504\vlaardingGlorie2Letzso.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="dd5324c8-5cb2-48e6-b0ff-f3542bb47875_vlaardingGlorie2Letzso.mp4" timescale="24000" duration="50584000" visible="1" square_pixel_height="720" square_pixel_width="1280" />
<asset media-type="4" type="vaSourcesManager" url="vaSourcesManager::URL" unique_id="Intensity Pro_1" name="Intensity Pro_1" video_tracks="1" audio_tracks="1" square_pixel_width="720" visible="1" square_pixel_height="576" sourceGUID="F5568E19-5437-4088-8EAD-F1A9813CA4DD" />
<asset name="live" unique_id="a1a3f2a4-09c9-4688-95ac-93d99290e32f_shot" type="shot" media-type="9" sort_on_normal="2" audio_tracks="1" video_tracks="1" still_image_tracks="0" alpha_track_count="1" veil_track_count="0" created_for_layer="2" visible="1" vam_state="8" />
<asset name="logo_live_popuptv.png" url="D:\wirecast\popuptv\logo\logo_live_popuptv.png" type="file" media-type="1" unique_id="dbba37ef-5927-454b-86bc-c7e45f496276_logo_live_popuptv.png" timescale="40" duration="40" alpha_track_count="1" square_pixel_height="1080" square_pixel_width="1920" visible="1" />
<asset name="live1" unique_id="a0e775f3-9d64-4665-b7d1-191beb42ea0b_shot" type="shot" media-type="9" duration="180000000" vam_state="8" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" sort_on_playlist="3" visible="1" audio_tracks="1" />
<asset name="logo_popuptv.png" url="D:\wirecast\popuptv\logo\logo_popuptv.png" type="file" media-type="1" unique_id="618d1281-f130-4c16-a2cb-84ac43f796b5_logo_popuptv.png" timescale="40" duration="40" alpha_track_count="1" square_pixel_height="1080" square_pixel_width="1920" visible="1" />
<asset name="leader" unique_id="25e1bc1e-711e-4f1d-8ac9-246c9c9d5837_shot" type="playlist_shot" media-type="9" vam_state="8" sort_on_normal="2" visible="1" created_for_layer="2" />
<asset name="Leader.mp4" url="D:\wirecast\waterwegsport\Leader.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="8881007b-e636-481f-a15e-3579ff38ab2f_Leader.mp4" timescale="25000" duration="323000" square_pixel_height="1080" square_pixel_width="1920" visible="1" />
<asset name="Naamtitel_Fred.mp4" url="D:\wirecast\waterwegsport\Naamtitel_Fred.mp4" type="file" video_tracks="1" media-type="1" unique_id="c6291487-799a-422d-9829-4d098a0fc551_Naamtitel_Fred.mp4" timescale="25000" duration="164000" square_pixel_height="1080" visible="1" square_pixel_width="1920" />
<asset name="Naamtitel_Roy.mp4" url="D:\wirecast\waterwegsport\Naamtitel_Roy.mp4" type="file" video_tracks="1" media-type="1" unique_id="a942381d-823c-4772-bc04-c13b22dd9de1_Naamtitel_Roy.mp4" timescale="25000" duration="164000" square_pixel_height="1080" visible="1" square_pixel_width="1920" />
<asset name="Naamtitel_leon.mp4" url="D:\wirecast\waterwegsport\Naamtitel_leon.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="1742b789-203f-4ace-a05f-4a1fc07c318a_Naamtitel_leon.mp4" timescale="25000" duration="164000" visible="1" square_pixel_height="1080" square_pixel_width="1920" />
<asset name="Outro.mp4" url="D:\wirecast\waterwegsport\Outro.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="8b18b2ff-29bb-463d-8782-9e1a255094bc_Outro.mp4" timescale="25000" duration="449000" visible="1" square_pixel_width="1920" square_pixel_height="1080" />
<asset name="outro" unique_id="e464133d-ea8f-489c-a963-676d1b6a1ca5_shot" type="playlist_shot" media-type="9" vam_state="8" created_for_layer="2" visible="1" />
<asset name="naamtitel_fred" unique_id="701be648-ab23-44c9-b16c-ac64869c98c9_shot" type="shot" media-type="9" vam_state="0" created_for_layer="1" visible="1" still_image_tracks="0" video_tracks="1" alpha_track_count="0" audio_tracks="0" veil_track_count="0" />
<asset name="naamtitel_roy" unique_id="b34811b6-58d5-4747-8990-e0154c41356b_shot" type="shot" media-type="9" vam_state="0" created_for_layer="1" visible="1" still_image_tracks="0" video_tracks="1" alpha_track_count="0" audio_tracks="0" veil_track_count="0" />
<asset name="naamtitel_leon" unique_id="9d5748b6-350f-4e28-a7ef-7962f8350037_shot" type="shot" media-type="9" vam_state="8" created_for_layer="1" visible="1" still_image_tracks="0" video_tracks="1" alpha_track_count="0" audio_tracks="1" veil_track_count="0" />
<asset name="Leader.mp4" unique_id="6258dfc5-c505-4ae3-96f7-5a2d387e5436_shot" type="shot" media-type="9" vam_state="8" duration="12000000" veil_track_count="0" alpha_track_count="1" audio_tracks="2" video_tracks="2" created_for_layer="2" shot_in_playlist="1" created_for_playlist="25e1bc1e-711e-4f1d-8ac9-246c9c9d5837_shot" sort_on_playlist="1" visible="1" still_image_tracks="0" />
<asset name="Outro.mp4" unique_id="441c9715-82c4-449a-8af7-1366575ccbac_shot" type="shot" media-type="9" vam_state="8" duration="17000000" video_tracks="2" still_image_tracks="0" veil_track_count="0" audio_tracks="2" created_for_layer="2" shot_in_playlist="1" created_for_playlist="e464133d-ea8f-489c-a963-676d1b6a1ca5_shot" sort_on_playlist="2" visible="1" alpha_track_count="1" />
<asset name="18 april was er weer de Culinaire Markt Schiedam 2015.mp4" url="D:\wirecast\popuptv\video\201504\18 april was er weer de Culinaire Markt Schiedam 2015.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="a9f676a7-3051-41f2-bee8-8cb4c9285aa8_18 april was er weer de Culinaire Markt Schiedam 2015.mp4" timescale="90000" duration="70041600" square_pixel_height="1080" visible="1" square_pixel_width="1920" />
<asset name="18 april was er weer de Culinaire Markt Schiedam 2015.mp4" unique_id="9d27c059-571e-41bd-bf27-957726ed862a_shot" type="shot" media-type="9" vam_state="8" sort_on_playlist="4" still_image_tracks="0" alpha_track_count="1" audio_tracks="1" video_tracks="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" veil_track_count="0" visible="1" />
<asset name="Komkids Kennisdag Schiedam 2015.mp4" url="D:\wirecast\popuptv\video\201504\Komkids Kennisdag Schiedam 2015.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="021f4fd9-5414-4979-b390-ddc637b16905_Komkids Kennisdag Schiedam 2015.mp4" timescale="90000" duration="37407600" square_pixel_height="1080" visible="1" square_pixel_width="1920" />
<asset name="Komkids Kennisdag Schiedam 2015.mp4" unique_id="a7e2ad99-f214-46af-9a50-c428b57357bf_shot" type="shot" media-type="9" sort_on_playlist="7" video_tracks="1" audio_tracks="1" still_image_tracks="0" vam_state="8" veil_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" alpha_track_count="1" visible="1" />
<asset name="Opening Servicepunt Woningverbetering nu op de Singel 85 in Schiedam.mp4" url="D:\wirecast\popuptv\video\201504\Opening Servicepunt Woningverbetering nu op de Singel 85 in Schiedam.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="eba37bd7-47d0-4246-8a21-17ab52722b68_Opening Servicepunt Woningverbetering nu op de Singel 85 in Schiedam.mp4" timescale="90000" duration="44744400" square_pixel_height="1080" square_pixel_width="1920" visible="0" />
<asset name="Opening Servicepunt Woningverbetering nu op de Singel 85 in Schiedam.mp4" unique_id="f56b1b55-bb26-4e4c-9220-0021809bab9a_shot" type="shot" media-type="9" sort_on_playlist="8" vam_state="8" still_image_tracks="0" veil_track_count="0" audio_tracks="1" video_tracks="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" visible="1" alpha_track_count="1" />
<asset name="Vld glorie live owe lullen band.mp4" url="D:\wirecast\popuptv\video\201504\Vld glorie live owe lullen band.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="97c72bcd-042a-4b8f-850f-f62d918b58f0_Vld glorie live owe lullen band.mp4" timescale="24000" duration="45174000" square_pixel_height="720" square_pixel_width="1280" visible="0" />
<asset name="Vld glorie live owe lullen band.mp4" unique_id="b512f5c5-937f-4964-af79-c9f522c65908_shot" type="shot" media-type="9" vam_state="14" alpha_track_count="0" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" visible="1" sort_on_playlist="9" />
<asset name="13-04-2015_Popuptv_opening culture candy2.mp4" url="D:\wirecast\popuptv\video\201504\13-04-2015_Popuptv_opening culture candy2.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="492d21bf-3290-47ac-ae1c-d90c1003462a_13-04-2015_Popuptv_opening culture candy2.mp4" timescale="25000" duration="7326000" square_pixel_height="1080" square_pixel_width="1920" visible="0" />
<asset name="13-04-2015_Popuptv_opening culture candy2.mp4" unique_id="1fe4622d-57d1-49db-a998-e1671b3553f5_shot" type="shot" media-type="9" vam_state="8" visible="1" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" alpha_track_count="0" sort_on_playlist="11" />
<asset name="De Maatschappij Vlaardingen V2_01-04-2015.mp4" url="D:\wirecast\popuptv\video\201504\De Maatschappij Vlaardingen V2_01-04-2015.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="ba77ead9-3a02-4fa5-85d2-e1c11ed9013d_De Maatschappij Vlaardingen V2_01-04-2015.mp4" timescale="50000" duration="10650000" square_pixel_height="1080" square_pixel_width="1920" visible="0" />
<asset name="De Maatschappij Vlaardingen V2_01-04-2015.mp4" unique_id="5a9b9eff-89d2-4c53-adb6-a9d5f8e4d917_shot" type="shot" media-type="9" sort_on_playlist="14" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" vam_state="8" visible="1" />
<asset name="popuptv_peuterfestival2.mp4" url="D:\wirecast\popuptv\video\201504\popuptv_peuterfestival2.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="159ea9af-d7d6-4b1a-a551-0ac295bfe274_popuptv_peuterfestival2.mp4" timescale="25000" duration="4460000" square_pixel_height="1080" square_pixel_width="1920" visible="0" />
<asset name="popuptv_peuterfestival2.mp4" unique_id="a81a8278-6a7b-4a41-ab50-72e2ceadb9d6_shot" type="shot" media-type="9" vam_state="8" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" sort_on_playlist="12" visible="1" />
<asset name="live4" unique_id="bdaf045e-5470-4997-adb7-4dac78f42d88_shot" type="shot" media-type="9" visible="1" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" alpha_track_count="1" sort_on_playlist="13" video_tracks="1" still_image_tracks="0" vam_state="8" audio_tracks="1" duration="180000000" veil_track_count="0" />
<asset name="live2" unique_id="766cd8dd-e0ba-4197-b203-1553f2b0eba7_shot" type="shot" media-type="9" vam_state="8" duration="180000000" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" alpha_track_count="1" visible="1" sort_on_playlist="6" />
<asset name="Live3" unique_id="2aadf2e7-2045-4d96-8192-b054c4c5e7b8_shot" type="shot" media-type="9" audio_tracks="1" duration="180000000" visible="1" sort_on_playlist="10" video_tracks="1" still_image_tracks="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" alpha_track_count="1" veil_track_count="0" vam_state="8" />
<asset name="Live5" unique_id="cd3d1da8-97f3-4720-b403-d05eb60ff641_shot" type="shot" media-type="9" duration="156000000" vam_state="8" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" visible="1" sort_on_playlist="16" alpha_track_count="1" />
<asset name="Uw videopitch .mp4" url="D:\wirecast\popuptv\video\201504\Uw videopitch .mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="dd6434de-d781-434b-8478-8944ff0dd2c8_Uw videopitch .mp4" timescale="25000" duration="252000" square_pixel_height="1080" square_pixel_width="1920" />
<asset name="Uw videopitch .mp4" unique_id="c5410859-4831-4dfe-83dd-b7692af12ddb_shot" type="shot" media-type="9" sort_on_playlist="5" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" vam_state="8" visible="1" />
<asset name="Like ons en volg ons.mp4" url="D:\wirecast\popuptv\video\201504\Like ons en volg ons.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="36e45769-499b-41c0-b317-907e71d59017_Like ons en volg ons.mp4" timescale="25000" duration="197000" square_pixel_height="1080" square_pixel_width="1920" />
<asset name="Like ons en volg ons.mp4" unique_id="eab7726e-7cae-4b7e-a69b-72e6ce347e6e_shot" type="shot" media-type="9" sort_on_playlist="15" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" vam_state="8" visible="1" />
<asset name="Nieuwsoverzicht Commercial.mp4" url="D:\wirecast\popuptv\video\201504\Nieuwsoverzicht Commercial.mp4" type="file" video_tracks="1" audio_tracks="1" media-type="1" unique_id="15e92e4c-1e52-4fe4-963f-be779ac7ce2e_Nieuwsoverzicht Commercial.mp4" timescale="25000" duration="239000" square_pixel_height="1080" square_pixel_width="1920" />
<asset name="Nieuwsoverzicht Commercial.mp4" unique_id="7eda8cc2-d51f-48e2-aa83-319c4a802912_shot" type="shot" media-type="9" sort_on_playlist="2" audio_tracks="1" video_tracks="1" still_image_tracks="0" veil_track_count="0" alpha_track_count="0" created_for_layer="2" shot_in_playlist="1" created_for_playlist="8228566d-0204-49ea-9089-7a8de978447c_shot" vam_state="8" visible="1" />
</assets>
这是我到目前为止在php中所拥有的。所有文件都按正确的顺序放置(基于属性&#34; sort_on_playlist&#34;)并显示文件的名称(不含.mp4),它只显示播放列表的数据&#34; programma&# 34;基于属性&#34; created_for_playlist&#34; ...
$xml = simplexml_load_file('teststream_001.wcst');
$alleAssets_naam=array();
$nodeNaam = $xml->assets->asset->attributes()->name;
foreach ($xml->assets->asset as $node) {
if ($node->attributes()->created_for_playlist=="8228566d-0204-49ea-9089-7a8de978447c_shot") {
$indexnummer =intval($node->attributes()->sort_on_playlist);
$naam=strval($node->attributes()->name);
$charnaam = strlen($naam);
if($charnaam > 7){
$naamkort = substr($naam, 0, -4);
}else{
$naamkort = $naam;
}
$a[$indexnummer] = $naamkort;
echo "<br/>nummer ",$indexnummer," is: ",$a[$indexnummer];
}
}
$max=count($alleAssets_naam);
for($i=0; $i<$max; $i++) {
echo "<br/>",$i," : ",$alleAssets_naam[$i];
}
我希望自己清楚明白,有人可以指出我正确的方向。
答案 0 :(得分:4)
以下代码将具有匹配名称的行合并为一个。最后,您将获得一个新的XML,其中每一行都包含您想要的内容。您现在可以迭代行并使用它们执行更多操作。
$doc = new \DOMDocument();
$doc->loadXML(/* Your XML goes here */);
$xPath = new \DOMXPath($doc);
$elements = $xPath->query('//asset[@name][@created_for_playlist]');
$newDoc = new \DOMDocument();
$newDoc->formatOutput = true;
$assetsElement = $newDoc->createElement('assets');
$newDoc->appendChild($assetsElement);
foreach($elements as $key => $element){
$name = $element->getAttribute('name');
$newAsset = $newDoc->importNode($element);
$searchResult = $xPath->query("//asset[@name='$name'][@duration]");
if(1== $searchResult->length){
foreach($searchResult->item(0)->attributes as $attribute){
$newAsset->setAttribute($attribute->name, $attribute->value);
}
$assetsElement->appendChild($newAsset);
}
}
echo $newDoc->saveXML();