【发布时间】:2020-07-31 04:26:20
【问题描述】:
我已获得要更新的 XML 文件,但在使用 XML 对象读取文件时,多个条目丢失。
XML 文件(注意两个 sectionGroup)
<configuration>
<configSections>
<sectionGroup name="Albert" type="Male, Outlook=neutral" >
<section name="Bobby" type="Male, Outlook=happy"/>
<section name="Cathy" type="Female, Outlook=neutral"/>
<section name="David" type="Male, History=Yes"/>
<sectionGroup name="Mark" type="Male, Outlook=happy" >
<section name="Matt" type="Male, Outlook=neutral"/>
</sectionGroup>
</sectionGroup>
</configSections>
</configuration>
脚本:
[XML] $xmlObj=Get-Content "C:\temp\infile.xml" -Raw
foreach ($elem in $xmlObj.configuration.configSections.sectionGroup.section)
{
Write-Host ("=> {0}='{1}'" -f $elem.name, $elem.type)
}
输出:
=> Bobby='Male, Outlook=happy'
=> Cathy='Female, Outlook=neutral'
=> David='Male, History=Yes'
请注意,不包括名字 (Albert) 或第二部分中的两个名字 (Mark, Matt)。
我无法更改多个 XML 文件,所以:
- 需要对代码进行哪些更改才能查看所有条目?
- 写回它们时,是否还需要进行其他更改?
【问题讨论】:
标签: json xml powershell