我無法從某些屬性獲取值。 下面是XML: -使用Groovy的XmlParser解析屬性值
def temp="""
<nodemetadata>
<imx:IMX xmlns:imx="http://com.abc.imx" xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:domainservice="http://com.abc.isp.metadata.domainservice/2">
<domainservice:GatewayNodeConfig imx:id="U:pgwraGgJbC99YpLSQ" consolePort="13993" consoleShutdownPort="4613" domainName="D_1163931" nodeName="N_1163931" dbConnectivity="ID_1">
<address imx:id="ID_2" xsi:type="common:NodeAddress" host="beetle" httpPort="1391" port="1392"/>
<portals>
<NodeRef imx:id="ID_3" xsi:type="common:NodeRef" address="ID_2" nodeName="N_1163931"/>
</portals>
</domainservice:GatewayNodeConfig>
<domainservice:DBConnectivity imx:id="ID_1" dbEncryptedPassword="AfaFnEtrQkOKFTVBYIIQ%3D%3D" dbHost="forer" dbName="ORCL" dbPort="1521" dbType="ORACLE" dbUsername="mka"/>
</imx:IMX>
</nodemetadata>
"""
def records = new XmlParser().parseText(temp)
def id='imx:id'
//Trying to get the value of imx:id from <domainservice:DBConnectivity >
log.info "Host = "+records.'imx:IMX'.'domainservice:DBConnectivity'[0].attribute(id)
也是我想知道如何得到這樣(的xmlns:XSI)任何標記值從線 -
感謝以下。
感謝你的回答,如果我想改變地址標記中'xsi:type'的值。我怎樣才能做到這一點。 – user3774346