【发布时间】:2018-10-03 19:51:02
【问题描述】:
我必须向 XML 文档添加一个新节点,而 Powershell 不允许我在我希望放置节点的位置使用 CreateElement() 方法。
我首先像这样获取 XML 文件的内容:
[XML]$val = Get-Content "path_to_XML_file"
然后使用$val.configuration.'system.webserver' 导航到我需要放置新元素的节点。
$val.configuration.'system.webserver'.GetType() 给我System.Xml.XmlLinkedNode
当我使用$val.configuration.'system.webserver'|gm 时,它只会给我以下选择:
ToString
AppendChild
Clone
CloneNode
CreateNavigator
Equals
GetAttribute
GetAttributeNode
GetElementsByTagName
GetEnumerator
GetHashCode
GetNamespaceOfPrefix
GetPrefixOfNamespace
GetType
HasAttribute
InsertAfter
InsertBefore
Normalize
PrependChild
RemoveAll
RemoveAllAttributes
RemoveAttribute
RemoveAttributeAt
RemoveAttributeNode
RemoveChild
ReplaceChild
SelectNodes
SelectSingleNode
SetAttribute
SetAttributeNode
Supports
WriteContentTo
WriteTo
由于节点是新节点,尝试使用AppendChild()没有效果。
还有其他方法可以创建节点吗?
谢谢。
【问题讨论】:
标签: xml powershell powershell-3.0