0

我将 XML 文件内容分配给一个变量$config,然后使用另一个变量$market来存储 XPath 查询的输出:

$config = Get-Content -Path "C:\files\configs\config.xml" -raw
$market = (select-xml -Content $config -xpath /process-config/input/filePattern/marketCode).node.'#text'

然后我添加以下行:

write-host this is $market

输出是这样的:

PS C:\ps_scripts> .\xmltest.ps1

this is citigroup_ams 
#text
-----
 citigroup_ams

我想要的输出是:

PS C:\ps_scripts> .\xmltest.ps1

    this is citigroup_ams 

我试图| Out-Null在第二行的末尾添加,但在这种情况下,只有 Write-Host cmdlet 的输出被抑制。有没有其他方法可以抑制输出Select-Xml

4

1 回答 1

0

You're probably looking for something like this :

$config = [xml]@'
  <process-config> 
    <input> 
      <filePattern> 
        <marketCode>citigroup_ams</marketCode>
      </filePattern>
    </input>  
  </process-config> 
'@
$market = $config.SelectNodes("/process-config/input/filePattern/marketCode/text()").Value
Write-Host "this is" $market

Output : this is citigroup_ams

于 2020-05-05T02:30:08.373 回答