我正在按照“实际操作”这本书,尝试从PowerShell文件中提取一些值,但是每次我尝试运行脚本时,Powershell都会报告意外的结束标记、意外的文件结束和其他事情,就好像源XML文件完全损坏了(但事实并非如此)。
脚本如下:
$config = Get-Content -path "C:\configs\ams\ams_merge_cgp.xml"
(Select-Xml -Content $config -XPath /process-config).Node"process-config“是源XML的根节点。
我得到了这样的错误:
Select-Xml : Cannot convert value " <input name="newsIn">" to type "System.Xml.XmlDocument". Error: "Unexpected end of file has occurred. The following elements are not closed: input. Line 1, position 23."
At C:\ps_scripts\xmltest.ps1:3 char:2
+ (Select-Xml -Content $config -XPath /process-config).Node发布于 2020-05-04 04:57:46
哦,我明白了。内容必须是一个字符串,而不是每行的字符串数组。
$config = get-content -path file.xml -raw
(select-xml -Content $config -xpath /process-config).node
input
-----
{newsIn, newsOut}您也可以只使用-path:
select-xml -xpath /process-config -Path file.xml | % n*
select-xml /process-config file.xml | % n*https://stackoverflow.com/questions/61580872
复制相似问题