【发布时间】:2019-10-14 18:09:05
【问题描述】:
我想向现有 XML 添加一个元素(连接器),这很成功,但我需要删除 xmlns= 并想为其添加一个值。连接器 blaat 与我的代码一起添加。
XML:
<?xml version="1.0"?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<connectors>
<!-- Connector used to be announced through cluster connections and notifications -->
<connector name="artemis">tcp://xxxxxxx:61616</connector>
<connector name="blaat" xmlns="" />
</connectors>
</core>
</configuration>
[xml]$xml = Get-Content d:\data\test-broker\etc\broker.xml
$xml.configuration.core.connectors.connector.ChildNodes.Item(0).value
$Node = $xml.CreateElement("connector");
$Node.SetAttribute("name", "blaat");
$xml.configuration.core.connectors.AppendChild($node)
$xml.configuration.core.connectors.connector.SetValue("tcp://");
$xml.Save("d:\data\test-broker\etc\broker.xml")
我希望 XML 是这样的:
<?xml version="1.0"?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<connectors>
<!-- Connector used to be announced through cluster connections and notifications -->
<connector name="artemis">tcp://xxxx1:61616</connector>
<connector name="blaat">tcp://xxxxx2:61616</connector>
</connectors>
</core>
</configuration>
【问题讨论】:
标签: xml powershell powershell-4.0