问题描述
我正在尝试使用 xmlstarlet 从 Wildfly 集群配置更新 host-slave.xml.
I am trying to update the host-slave.xml from a Wildfly Cluster configuration with xmlstarlet.
我正在使用以下语句:
xml ed -N my=urn:jboss:domain:2.2 -u "_:host/management/security-realms/security-realm[@name='UndertowRealm']/server-identities/ssl/keystore/@path" -v "test" Wildfly\wildfly-8.2.0.Final\WildFly-HOST\configuration\host-slave.xml
xml 中的命名空间定义:
The namespace definition in xml:
<host name="172.16.1.11" xmlns="urn:jboss:domain:2.2" >
我要更改的xml部分:
The part of the xml I want to change:
<security-realm name="UndertowRealm">
<server-identities>
<ssl>
<keystore path="D:\wildfly-8.2.0.Final\ssl\wildfly.keystore" keystore-password="rsaddbTsadYvvMXZ" alias="wildfly" />
</ssl>
</server-identities>
</security-realm>
但是如果我从 xml 中删除命名空间定义,并使用以下语句:
But if I delete the namespace defition from the xml, and use the following statement:
xml ed -u ":host/management/security-realms/security-realm[@name='UndertowRealm']/server-identities/ssl/keystore/@path" -v "test" Wildfly\wildfly-8.2.0.Final\WildFly-HOST\configuration\host-slave.xml
它按预期工作,所以它不是 XPATH 的问题.因为我不知道如果我删除命名空间声明会发生什么wildfly,我想保留它.
It works as expected, so it is not an Issue with XPATH.As I dont know what happens to wildfly if I delete the namespace declaration, I would like to keep it.
推荐答案
问题是您需要使用声明的前缀(my
,您正确映射到默认命名空间 URI)来引用XPath 中该命名空间中的元素,例如:
The problem is that you need to use the declared prefix (my
, which you correctly mapped to the default namespace URI) to reference element in that namespace in your XPath, for example :
/my:security-realm[@name='UndertowRealm']/my:server-identities/my:ssl/my:keystore/@path
基本上,所有没有前缀的元素,在声明默认命名空间的元素中,都被认为是在同一个默认命名空间中,因此需要使用前缀my
来引用.
Basically, all element without prefix, within element where default namespace is declared, are considered in the same default namespace, hence need to be referenced using the prefix my
.
这篇关于使用 xmlstarlet 1.6.1 更新带有命名空间的 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!