Reputation: 179
I have a question, I want to fetch an attribute from one XML and use the same fetched value for another XML. Sounds pretty easy but there is one thing I need to get around. My first XML looks like this here:
<?xml version="1.0" encoding="UTF-8"?>
<ffprobe>
<streams>
<stream index="0" codec_name="prores" codec_long_name="ProRes" codec_type="video" codec_time_base="1/24" codec_tag_string="apcs" codec_tag="0x73637061" width="1920" height="1080" has_b_frames="0" sample_aspect_ratio="0:1" display_aspect_ratio="0:1" pix_fmt="yuv422p10le" level="-99" r_frame_rate="24/1" avg_frame_rate="24/1" time_base="1/24" start_pts="0" start_time="0.000000" duration_ts="1152" duration="48.000000" bit_rate="13174677" nb_frames="1152" nb_read_frames="1152">
<disposition default="1" dub="0" original="0" comment="0" lyrics="0" karaoke="0" forced="0" hearing_impaired="0" visual_impaired="0" clean_effects="0" attached_pic="0"/>
<tag key="creation_time" value="2013-10-10 02:59:14"/>
<tag key="language" value="eng"/>
<tag key="handler_name" value="DataHandler"/>
</stream>
</streams>
</ffprobe>
There I grab the nb_frames
attribut and save it in a parameter called $totalframes
:
$xmlpfad = [xml](Get-Content C:\Users\Administrator\Desktop\input_dcp\$filename+totalframes.xml)
[string]$totalframes = $xmlpfad.ffprobe.streams.stream | select nb_frames
Now when I try to use this value for my second XML I get something like:
<NumOfRepetitions>@{nb_frames=1152}</NumOfRepetitions>
But I only need the value 1152 itself, without @{nb_frames=}
is this possible in some kind of way?
Upvotes: 0
Views: 263
Reputation: 4838
Your totalframes
variable will be an object which has a property called nb_frames
.
In order to get only the value of the property, you need to use the -ExpandProperty
parameter to the Select
cmdlet. So change the last line to:
[string]$totalframes = $xmlpfad.ffprobe.streams.stream | select -ExpandProperty nb_frames
Upvotes: 1