Parsing an XML with Powershell -


i need read through xml file , count how many representation elements there in first adaptationset, because everytime xml generated can have varying amounts 1 10. i'm new powershell , using xdoc read xml file.

<?xml version="1.0" encoding="utf-8"?> <mpd xmlns:xsd="http://www.w3.org/2001/xmlschema" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" id="111091661:1853125475:ntsc" profiles="urn:mpeg:dash:profile:isoff-live:2011 urn:com:dashif:dash264" type="dynamic" availabilitystarttime="2015-07-09t18:47:42.8780481" publishtime="2015-07-09t18:47:41.7236461" minimumupdateperiod="pt3600s" minbuffertime="pt15s" timeshiftbufferdepth="pt60s" suggestedpresentationdelay="pt30s" maxsegmentduration="pt1.000s" xsi:schemalocation="urn:mpeg:dash:schema:mpd:2011 dash-mpd.xsd" xmlns="urn:mpeg:dash:schema:mpd:2011">   <period id="1" start="pt0s">     <adaptationset framerate="30000/1001" mimetype="video/mp4" codecs="avc1.4d401e" startwithsap="1" segmentalignment="true">       <segmenttemplate timescale="30000" duration="30030" startnumber="0" media="$bandwidth$/$number$.m4v" initialization="$bandwidth$/0.m4s" />       <representation width="314" height="210" id="v0" bandwidth="300000" />       <representation width="614" height="414" id="v1" bandwidth="1150000" />       <representation width="720" height="486" id="v2" bandwidth="2000000" />     </adaptationset>     <adaptationset mimetype="audio/mp4" codecs="mp4a.40.2" startwithsap="1" segmentalignment="true">       <segmenttemplate timescale="48000" duration="48048" startnumber="0" media="audio/$number$.m4a" initialization="audio/0.m4s" />       <representation id="a0" bandwidth="448000" />     </adaptationset>   </period> </mpd> 

you can use select-xml select nodes xpath expression:

(     select-xml -namespace @{ns='urn:mpeg:dash:schema:mpd:2011'} `                -xpath //ns:adaptationset[1]/ns:representation `                -path test.xml |     measure-object ).count 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -