我正在尝试使用powershell命令select-xml从xml文件中选择数据。当我在下面运行命令时,没有结果或错误返回。我希望版本列表会返回到屏幕。这怎么了
PS C:\> select-xml -path "C:\t.xml" -xpath "//edition" | foreach {$_.node.InnerXML}
PS C:\>
XML文件(C:\ t.xml)为:
<?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>
最佳答案
做到这一点的另一种方法是:
PS H:\> $xml = ([xml](Get-Content -Path C:\scripts\t.xml)).Book.Projects.Project
PS H:\> $xml.editions | select -ExpandProperty Edition
language #text
-------- -----
English En.Book1.com
German Ge.Book1.Com
French Fr.Book1.com
Polish Pl.Book1.com