regex - Match particular CDATA sections in XML data -
i trying powershell regex, have following page (further below) want match from, 2 parts in bold information want capture , assign variable. need 2 regex's. text below, 2 area's need find king , years & years. please note, these 2 areas change (hence reason need capture them), rest of of code stays same.
this regex have @ moment, it's not working me.
\s+artist\s*>\s*<\s*!\s*[cdata\s*[(.*)\s*]\s*]\s*>\s*<\s*/artist
and here page (or data) trying use regex with.
<on_air> <publishedinfo publisheddate="2015-07-18 16:24:28" /> <stationname><![cdata[mix 106.5]]></stationname> <stationprefix><![cdata[mix1065]]></stationprefix> <generic_coverart><![cdata[http://media.arn.com.au/images/getimage.aspx?i=generic_mix1065.jpg]]></generic_coverart> <now_playing> <audio id="id_1705168034_30458146" type="song"> <title generic="false"><![cdata[king*]]></title> <artist><![cdata[years & years]]></artist> <number><![cdata[46029]]></number> <cut><![cdata[1]]></cut> <ref><![cdata[]]></ref> <played_datetime><![cdata[2015-07-18 16:24:27]]></played_datetime> <length><![cdata[00:03:28]]></length> <coverart generic="true"><![cdata[http://media.arn.com.au/images/getimage.aspx?i=generic_mix1065.jpg]]></coverart> <options> <option><![cdata[kiis s integrated]]></option> </options> </audio> </now_playing>
if valid xml, not need use regular expressions. powershell adapt xml objects , can use standard property syntax navigate on them:
$xml=[xml]@' <on_air> <publishedinfo publisheddate="2015-07-18 16:24:28" /> <stationname><![cdata[mix 106.5]]></stationname> <stationprefix><![cdata[mix1065]]></stationprefix> <generic_coverart><![cdata[http://media.arn.com.au/images/getimage.aspx?i=generic_mix1065.jpg]]></generic_coverart> <now_playing> <audio id="id_1705168034_30458146" type="song"> <title generic="false"><![cdata[king*]]></title> <artist><![cdata[years & years]]></artist> <number><![cdata[46029]]></number> <cut><![cdata[1]]></cut> <ref><![cdata[]]></ref> <played_datetime><![cdata[2015-07-18 16:24:27]]></played_datetime> <length><![cdata[00:03:28]]></length> <coverart generic="true"><![cdata[http://media.arn.com.au/images/getimage.aspx?i=generic_mix1065.jpg]]></coverart> <options> <option><![cdata[kiis s integrated]]></option> </options> </audio> </now_playing> </on_air> '@ $xml.on_air.now_playing.audio.title.'#cdata-section' $xml.on_air.now_playing.audio.artist.'#cdata-section'
Comments
Post a Comment