I’m trying to use the powershell command select-xml to select data from an xml file. When I run the command below no results or errors are returned. I expect a list of the editions to be returned to the screen. What’s wrong with this?
PS C:\> select-xml -path "C:\t.xml" -xpath "//edition" | foreach {$_.node.InnerXML}
PS C:\>
The XML file (C:\t.xml) is:
<?xml version="1.0" encoding="utf-8"?>
<Book>
<projects>
<project name="Book1" date="2009-01-20">
<editions>
<edition language="English">En.Book1.com</edition>
<edition language="German">Ge.Book1.Com</edition>
<edition language="French">Fr.Book1.com</edition>
<edition language="Polish">Pl.Book1.com</edition>
</editions>
</project>
</projects>
</Book>
OK, so I know what’s wrong. There was one white space character before the first node of the XML declaration. Really annoying. I tried your first line:
It errored with:
I’m sure that the select-xml should fail in the question with this same error when attempting to read an xml file. The xml file rendered fine in IE.