【发布时间】:2015-02-11 07:24:16
【问题描述】:
我有以下 XML:
<?xml version="1.0" encoding="UTF-8"?>
<video publishState="Published" xmlns="urn:schemas-microsoft-com:msnvideo:catalog">
<uuid>ed255a56e807</uuid>
<title>ABCD</title>
<description>ABCD</description>
<startDate>2014-06-12T06:30:00Z</startDate>
<activeEndDate>2017-06-01</activeEndDate>
<searchableEndDate>2017-06-01</searchableEndDate>
<archiveEndDate>2019-05-22</archiveEndDate>
<videoFiles>
<videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="400" width="320" height="180" fileSize="9654368" msnFileId="ED0ADD1E-7C36-472E-8186-5C43DDCCD58C" formatCode="101">
<uri>http://e2/ds/977d13e5-285f-4fe3-b49c-a6b604e89c22.mp4</uri>
</videoFile>
<videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="600" width="640" height="360" fileSize="14911095" msnFileId="59AB7AE5-15F3-4EA8-ABD9-92E1A1CE0424" formatCode="102">
<uri>http://e2/ds/0aaad23d-bcb1-48e4-85c7-788b58ab8ae6/ds/3f4b77a3-3157-48a4-88b5-df854025cfe5.mp4</uri>
</videoFile>
<videoFile msnFileId="EDAA3798-B16B-435F-A9CA-6B1D07729D44" formatCode="1001" fileHash="ebc2f23aba9f0ff8d0146a052089a34f">
<uri>ftp://handler_20140611_highlight_b_222747.mp4</uri>
</videoFile>
<videoFile sourceFileHash="ebc2f23aba9f0ff8d0146a052089a34f" bitrate="3000" width="1280" height="720" fileSize="70668740" msnFileId="9505AEF2-7742-4BB1-9427-F07185D6FC9B" formatCode="104">
<uri>http://e2/ds/a2e1563f-c9a3-41f7-97fe-e024742c6bbf.mp4</uri>
</videoFiles>
</video>
我正在尝试获取formatCode="1001" 的URI 值。但是,由于它是一个数组,因此我无法这样做。在到达formatCode =1001 时,数组$uri 的所有值都会打印在控制台上。我尝试过使用 Where 子句,例如 | Where {$xml.video.videoFiles.videoFile.formatCode -eq 1001 },但这也没有帮助。
我正在使用以下代码:
Get-ChildItem D:\video*.xml | ForEach-Object
{
$xml = [xml] (Get-Content $_.fullname)
# $xml.video.videoFiles.videoFile | Where-Object { $_.formatCode -eq 1001 } | Format-Table msnFileId, uri
$out = New-Object PSObject
$out | Add-Member NoteProperty UUID -Value $xml.video.uuid.innertext
$out | Add-Member NoteProperty EndDate -Value $xml.video.activeEndDate
Foreach ($uri in $xml.video.videoFiles.videoFile.uri)
{
if ($xml.video.videoFiles.videoFile.formatCode -eq 1001)
{
$temp1 = [string]$uri
}
}
$out | Add-Member NoteProperty URI -Value $temp1
Write-Output $out
}
【问题讨论】:
标签: arrays xml powershell video