您可以解决相关问题
instance
具有如下XPath表达式的节点:
//class[@type = 'I want to filter on whatever value this is']/instance
$xml |Select-Xml -XPath "//class[@type = 'I want to filter on whatever value this is']/instance" |ForEach-Object {
[pscustomobject]@{
QuestionSetName = ($_.Node |Select-Xml "./property[@name='QuestionSetName']").Node.InnerText
Ratio = ($_.Node |Select-Xml "./property[@name='Ratio']").Node.InnerText
}
}
如果你有很多
<property />
要为每个元素枚举的元素
<instance />
$propertyNames = 'QuestionSetName','Ratio','Size','SomeOtherProperty'
$xml |Select-Xml -XPath "//class[@type = 'I want to filter on whatever value this is']/instance" |ForEach-Object {
$properties = [ordered]@{}
foreach($name in $propertyNames){
$properties[$name] = ($_.Node |Select-Xml "./property[@name='${name}']").Node.InnerText
}
[pscustomobject]$properties
}