I am new to groovy.
Trying to parse some xml request, without luck for some time.
As Final result:
- I want to check if xml request "RequestRecords" has "DetailsRequest" atrribute;
- Get "FieldValue" number where "RequestF" has FieldName="Id".
Also, for some reason I cannot use XmlSlurper as it returns false to 'def root = new XmlParser().parseText(xml)'.
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
Even assertion of root node fails.