我正在阅读 groovy 中的 xml 文件,如下所示,但不知道出了什么问题。
下面是我的功能
def setEnvironment(Map env,Map params)
{
def records=new XmlSlurper().parse(env.get("ABC_HOME")+"/isp/config/nodemeta.xml")
def jdbcurl=records.'domainservice:DBConnectivity'[0].@dbConnectString
params.put("dn", records.'domainservice:GatewayNodeConfig'[0].@domainName)
params.put("dh", records.'domainservice:GatewayNodeConfig'[0].'address'[0].@host)
params.put("dp", records.'domainservice:GatewayNodeConfig'[0].'address'[0].@httpPort)
params.put("u", records.'domainservice:DBConnectivity'[0].@dbUsername)
if(jdbcurl==null||jdbcurl.size()==0)
{
params.put("tns", records.'domainservice:DBConnectivity'[0].@dbHost)
}
else
{
params.put("tns", jdbcurl.find("(?<=%2F%2F)[\\d\\w_]+"))
}
println params
}
我的输出
[pd:admin, u:, tns:, dh:, dn:, dp:, un:admin, x:c1164035531]
我的 XML
<?xml version="1.0" encoding="UTF-8"?>
<imx:IMX xmlns:imx="http://com.abc.imx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" serializationSpecVersion="4.0" crcEnabled="0" xmlns:domainservice="http://com.abc.isp.metadata.domainservice/2" versiondomainservice="2.4.1" xmlns:common="http://com.abc.isp.metadata.common/2" versioncommon="2.2.0" xsi:schemaLocation="http://com.abc.imx IMX.xsd http://com.abc.isp.metadata.domainservice/2 com.abc.isp.metadata.domainservice.xsd http://com.abc.isp.metadata.common/2 com.abc.isp.metadata.common.xsd">
<domainservice:GatewayNodeConfig imx:id="U:LtWHxY0ZEeGb2FwhP-xoGw" adminconsolePort="15533" adminconsoleShutdownPort="38207" domainName="D_1035531" nodeName="N_1035531" dbConnectivity="ID_1">
<address imx:id="ID_2" xsi:type="common:NodeAddress" host="absdie" httpPort="1531" port="1532"/>
<portals>
<NodeRef imx:id="ID_3" xsi:type="common:NodeRef" address="ID_2" nodeName="N_1035531"/>
</portals>
</domainservice:GatewayNodeConfig>
<domainservice:DBConnectivity imx:id="ID_1" dbEncryptedPassword="ZmTXZDoYq0TyrU7fSaS9BrAlIuZyS2rw%2FafW1TLWE4g%3D" dbHost="fortuner" dbName="ORCL" dbPort="1521" dbType="ORACLE" dbUsername="zx1649355388"/>
</imx:IMX>
注意:pd & x 已经在地图中了