【发布时间】:2021-01-07 00:26:27
【问题描述】:
我将以这个示例数据为例:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</catalog>
数据链接:https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms762271(v=vs.85)
假设我想查询作者和价格
[xml]$XmlFileObj = Get-Content 'C:\Users\David\Documents\XmlSample.dtsx'
$XmlFileObj | Select-Xml -XPath "/catalog/book/author | /catalog/book/price " | Select-Object -ExpandProperty Node
结果是:
#text
-----
Gambardella, Matthew
44.95
Ralls, Kim
5.95
如果我希望结果看起来像:
#col1; col2
-----
Gambardella, Matthew; 44.95
Ralls, Kim ; 5.95
或者类似的表格形式...
【问题讨论】:
标签: xml powershell xpath