Reputation: 597
I'm following along "Windows PowerShell in Action" book and trying to extract some values from an XML file, however each time i try to run script, Powershell complains about unexpected end tag, unexpected end of file and other things, as if the source XML file was totally corrupt (but it is not).
Here is the script:
$config = Get-Content -path "C:\configs\ams\ams_merge_cgp.xml"
(Select-Xml -Content $config -XPath /process-config).Node
"process-config" is the root node of the source XML.
I get this kind of errors:
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
Upvotes: 1
Views: 827
Reputation: 27408
Oh, I see. The content has to be one string, not an array of strings for each line.
$config = get-content -path file.xml -raw
(select-xml -Content $config -xpath /process-config).node
input
-----
{newsIn, newsOut}
You could also just use -path:
select-xml -xpath /process-config -Path file.xml | % n*
select-xml /process-config file.xml | % n*
Upvotes: 2