Я думаю, что вы спрашиваете, как найти <module>
, который на самом деле имеет элемент комментария непосредственно за ним в XML, верно?
В этом случае, вот что может это сделать:
[xml]$xmlFile = @"
<project>
<modules>
<module>com.umut.web</module>
<module>com.umut.oaservice</module><!--auto-->
<module>com.umut.signaturephotoservice</module>
</modules>
</project>
"@
foreach ($node in $xmlFile.project.modules.ChildNodes) {
if ($node.NodeType -eq 'Comment') {
# if this comment node following a childnode within 'modules'
if ($node.PreviousSibling) {
[PSCustomObject]@{
'module' = $node.PreviousSibling # the module element (System.Xml.XmlElement object)
'moduleText' = $node.PreviousSibling.InnerText # the text inside this module element
'comment' = $node # the comment element (System.Xml.XmlComment)
'commentText' = $node.InnerText # the text inside the comment
}
break
}
}
}
Он генерирует объект PSCustomObject с четырьмя свойствами или ничего, если поиск не дал результата.
module moduleText comment commentText
------ ---------- ------- -----------
module com.umut.oaservice #comment auto