【发布时间】:2021-03-23 15:11:37
【问题描述】:
Select-Xml 的使用方法如下:
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> Select-Xml
cmdlet Select-Xml at command pipeline position 1
Supply values for the following parameters:
Xml[0]: ./bookstore.xml
Xml[1]:
XPath: /bookstore
Select-Xml: Cannot bind parameter 'Xml'. Cannot convert the "./bookstore.xml" value of type "System.String" to type "System.Xml.XmlNode".
PS /home/nicholas/powershell>
通过上面的 REPL 输入参数和 Xpath。当然:
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> $doc = New-Object xml
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> $doc.Load( (Resolve-Path ./bookstore.xml) )
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> Select-Xml "./bookstore.xml" -XPath "/bookstore/book/title" | foreach {$_.node.InnerXML}
Pride And Prejudice
The Handmaid's Tale
Emma
Sense and Sensibility
PS /home/nicholas/powershell>
PS /home/nicholas/powershell> cat ./bookstore.xml
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore xmlns:bk="urn:samples">
<book genre="novel" publicationdate="1997" bk:ISBN="1-861001-57-8">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992" bk:ISBN="1-861002-30-1">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="novel" publicationdate="1991" bk:ISBN="1-861001-57-6">
<title>Emma</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982" bk:ISBN="1-861001-45-3">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
</bookstore>
PS /home/nicholas/powershell>
工作fine。
这个问题被大量编辑。
我不希望交互式提示被广泛使用。
如果有人使用它,太好了。否则,为了我的目的,这个问题得到了回答。
【问题讨论】:
-
我想如果你想指定一个路径使用例如
Select-Xml -Path .\bookstore.xml -XPath //book/title -
所以,这就像你的其他帖子一样。 stackoverflow.com/questions/65264156/…,我回复了。那么,我们是否为您/与您一起做作业? ;-}
标签: xml powershell xpath xquery select-xml