我有下面的Powershell代码,其中在执行时,$b4有一个字符串值,但是一旦我以任何方式修改了DOM并试图访问XmlDocument属性,比如OuterXml,我在$after中就得不到任何值。
我相信这是某种类型的铸造问题,但我不能确定原因。
$xml = [xml]"<root></root>"
$comment = $xml.CreateComment("<!-- added from comment -->" )
$b4 = $xml.OuterXml #this has a value as expected
$xml.FirstChild.AppendChild($comment)
$after = $xml.OuterXml #This is empty string or null修改DOM后如何获取$xml的OuterXml值?
发布于 2016-08-19 22:24:22
据我所知,你只需要在创建评论时删除<!--和-->即可。如下所示:
$xml = [xml]"<root></root>"
$comment = $xml.CreateComment("added from comment") #From here
$b4 = $xml.OuterXml #this has a value as expected
$xml.FirstChild.AppendChild($comment)
$after = $xml.OuterXml #Not nullhttps://stackoverflow.com/questions/39041172
复制相似问题