下面将显示一个子元素,当且仅当它位于第一个父元素中时。Select-Xml仅显示第一个节点中的子节点
$xml = @"
<?xml version="1.0" encoding="utf-8"?>
<root>
<par><commonchild>Hi there.</commonchild><otherchild>This is displayed.</otherchild></par>
<par><commonchild>Hi again.</commonchild><otherchild>So is this.</otherchild></par>
<par><commonchild>Well hello.</commonchild><missingchild>This is missing.</missingchild></par>
<par><commonchild>Cheers.</commonchild><missingchild>So is this.</missingchild></par>
</root>
"@
cls
Select-Xml -Content $xml -XPath "//par" | select -ExpandProperty node
输出
commonchild otherchild
----------- ----------
Hi there. This is displayed.
Hi again. So is this.
Well hello.
Cheers.
我们怎样才能显示,而不是所有的父母的所有子元素?例如,下面的作品,但有时我们不知道所有的子元素名称。
cls
Select-Xml -Content $xml -XPath "//par" |
select -ExpandProperty node |
select commonchild, otherchild, missingchild
输出
commonchild otherchild missingchild
----------- ---------- ------------
Hi there. This is displayed.
Hi again. So is this.
Well hello. This is missing.
Cheers. So is this.
明星是“任何” - 很可能是'/ * *? –
@AlexeiLevenkov那不行。 –
它不做什么? 'Select-Xml -Content $ xml -XPath“// *”'给你所有的节点......你只需要弄清楚如何处理它们,因为“all”包含'root'作为第一个节点,我认为它会混淆输出...尝试'/根// *'与您的原始代码有些非空输出 –