【发布时间】:2016-08-24 04:11:30
【问题描述】:
在验证 XML 文件中的 id 时,它是区分大小写的。我添加了“翻译”以使其不区分大小写。以下是我的代码:
$Config = "xmlfile"
[xml]$configxml = Get-Content $config
$siteId = "Test"
$Siteid = $Siteid.ToLower()
$siteinfo = $configxml.SelectSingleNode("/configuration/environment[translate(@id='$($siteId)'])");
if(!$siteinfo)
{
Write-Host "id specified '$siteId' not found in '$config' Aborting..."
exit -1
}
else
{
Write-Host "site id is present"
}
我收到以下错误:
id specified 'Test' not found in 'xmlfile' Aborting...
这是我的 xml 文件:
<configuration>
<!-- TEST -->
<environment id="TEST">
<client>ABC</client>
<type>Test</type>
<filetype>ALL</filetype>
<enable>yes</enable>
</environment>
</configuration>
有人可以建议我可能的解决方案如何使其不区分大小写以及如何使用“翻译”?
【问题讨论】:
标签: xml powershell xpath case-sensitive