combine xml childs with same attribute in php -


i have surfed on web , tried different aproaches trying achieve want, doesn't work. hope of can point me in right direction.

i have xml file multiple childs has same "name" attribute. 1 child need attributes "created_for_playlist" , "sort_on_playlist" , other child same "name" attribute need "name" , "duration". both childs has different attributes...

is possible information , merge xml or write direct in array or print or echo directly?

this 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 er weer de culinaire markt schiedam 2015.mp4" url="d:\wirecast\popuptv\video\201504\18 april 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 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 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> 

this have far in php. files placed right order (based on attribute "sort_on_playlist") , shows name of file (without .mp4) , shows data of playlist "programma" based on attribute "created_for_playlist"...

$xml = simplexml_load_file('teststream_001.wcst'); $alleassets_naam=array();  $nodenaam = $xml->assets->asset->attributes()->name;  foreach ($xml->assets->asset $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]; } 

i hope made myself clear , can point me in right direction.

the following code combine rows matching names one. @ end have new xml every row contains wanted. can iterate on rows , more stuff them.

$doc = new \domdocument(); $doc->loadxml(/* 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 $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 $attribute){             $newasset->setattribute($attribute->name, $attribute->value);         }         $assetselement->appendchild($newasset);     } }  echo $newdoc->savexml(); 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -