使用带有xml sluper的groovy删除部分xml

时间:2013-05-27 08:59:49

标签: xmlslurper

我很喜欢groovy,所以作为我的任务的一部分,我需要更新xml。

我的xml是::

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<root xmlns="">
<queries>


<query list="true" type="Query">
<retrieve extent="3" offset="0" size="10000" subtype="uk.co.netdev.icr.provisioning.data.Corp">
<criteria list="true" type="Criteria">
<string-criteria expression="IAS" field-name="name"/>
</criteria></retrieve></query>
</queries></root></in0></soapenv:Body></soapenv:Envelope>

从这个xml我需要删除一部分xml,并应将输出打印为::

<root xmlns=""><queries><query list="true" type="Query"><retrieve extent="3" offset="0" size="10000" subtype="uk.co.netdev.icr.provisioning.data.Corp"><criteria list="true" type="Criteria"><string-criteria expression="IAS" field-name="name"/></criteria></retrieve></query></queries></root>

请建议, 感谢。

1 个答案:

答案 0 :(得分:0)

我想这就是你需要的:

def soapMsg = new XmlSlurper().parseText(inputXml);
def output = groovy.xml.XmlUtil.serialize(soapMsg.Body.root)

顺便说一下,你上面的输入XML有一些额外的标签:“&lt; / in0&gt;”