我是groovy的新手。Groovy xml请求解析
试图解析一些XML请求,没有运气一段时间。
至于最终结果:
- 我要检查,如果XML请求 “RequestRecords” 有 “DetailsRequest” atrribute;
- 获得“FieldValue”号码,其中“RequestF”具有FieldName =“Id”。
此外,由于某种原因,因为它返回false为 'DEF根=新XmlParser的()。parseText(XML)' 我不能使用的XmlSlurper。
def env = new groovy.xml.Namespace("http://schemas.xmlsoap.org/soap/envelope/", 'env');
def ns0 = new groovy.xml.Namespace("http://tempuri.org/", 'ns0')
def xml = '''<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://tempuri.org/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<env:Body>
<ns0:Request1>
<ns0:Request_Sub>
<ns0:RequestRecords TableName="Header">
<ns0:RequestF FieldName="SNumber" FieldValue="XXX"/>
<ns0:RequestF FieldName="TNumber" FieldValue="30"/>
</ns0:RequestRecords>
<ns0:RequestRecords TableName="Details">
<ns0:RequestF FieldName="Id" FieldValue="1487836040"/>
</ns0:RequestRecords>
</ns0:Request_Sub>
<ns0:isOffline>false</ns0:isOffline>
</ns0:Request1>
</env:Body>
</env:Envelope>'''
def root = new XmlParser().parseText(xml)
println ("root" + root)
assert "root_node" == root.name()
println root_node
根节点即使断言失败。
那么,正确的说法应该是在这种情况下? assert root.name()=='Envelope' 也失败。 –
在断言之前添加'println'root [$ {root.name}]''以验证它是什么很容易。它为我显示了“信封”。 –