I assigned XML file contents to a variable $config
and then used another variable $market
to store the output of XPath query:
$config = Get-Content -Path "C:\files\configs\config.xml" -raw
$market = (select-xml -Content $config -xpath /process-config/input/filePattern/marketCode).node.'#text'
Then I add the following line:
write-host this is $market
And the output is this:
PS C:\ps_scripts> .\xmltest.ps1
this is citigroup_ams
#text
-----
citigroup_ams
My desired output would be:
PS C:\ps_scripts> .\xmltest.ps1
this is citigroup_ams
I attempted to add | Out-Null
| Out-Null
at the end of the 2nd line but in this case only the output of Write-Host cmdlet was suppressed. Is there any other way to suppress the output of Select-Xml
?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.