我有一个操作生成的XML文件。我需要通过PowerShell为以下XML文件提取一些值。
<TABLE BORDER=0><TR><TD><img src="/_file.gif"<A HREF="/TestSandbox-Build-Artifacts/TB-Alpha-App_Installer.apk">Bubbles_Install_13</a> </TD><TD ALIGN=right>2459427535 bytes </TD><TD>Jul 1, 2019 12:35:52 AM</TD></TR>
<TR><TD><img src="/_file.gif alt="(file)"> <A HREF="/Test/sharTestSandbox-Build-Artifacts/UnitTests.zip">UnitTests.zip</a> </TD><TD ALIGN=right>435316365 bytes </TD><TD>Jul 1, 2019 12:36:10 AM</TD></TR>
<TR><TD><A HREF="/Test/shared/build-latest/TestSandbox-Build-Artifacts/buildInfo.json">buildInfo.json</a> </TD><TD ALIGN=right>220 bytes </TD><TD>Jul 1, 2019 12:36:10 P<M</TD></TR>
</TABLE>
</BODY>
我在PowerShell中尝试了几个命令,但是它们都给出了相同的错误。
$file = "C:\Users\amit\Desktop\Builds\Output.xml"
$xml = [xml](Get-Content $file)
$file = "C:\Users\amit\Desktop\Builds\Output.xml"
$xml = New-Object XML
$xml.Load($file)
对于第一个命令,出现以下错误。
Cannot convert value "System.Object[]" to type "System.Xml.XmlDocument". Error: "'0' is an unexpected token. The expected token is '"' or '''. Line 2, position 48." At line:4 char:1 $xml = [xml](Get-Content $file) + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidCastToXmlDocument
对于第二个命令
Exception calling "Load" with "1" argument(s): "'0' is an unexpected token. The expected token is '"' or '''. Line 2, position 48." At line:6 char:1 $xml.Load($file) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
如果生成的输出文件有问题或我的语法有问题,我将无法获取。