[英]Select module which is the have the comment with Powershell
我想选择具有注释行的模块。
<modules>
<module>com.umut.web</module><!--auto-->
<module>com.umut.oaservice</module>
<module>com.umut.signaturephotoservice</module>
</modules>
powershell代码=
[string]$modules=""
foreach ($module in $xmlFile.project.modules.module) {
Write-Output $module.'#comment'
}
我想你要问的是如何找到实际上在xml后面直接有注释元素的<module>
,对吧?
在这种情况下,这可能是这样的:
[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
我认为你在你的foreach
走得太远了。
如果你做了怎么办:
[string]$modules=""
foreach ($module in $xmlFile.project.modules) {
Write-Output $module.'#comment'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.