Groovy web console

subscribe to the feed Subscribe
to this
site
parse xml and assert (via #groovywebconsole)
tweet this snippet Tweet
this
script

parse xml and assert

Published 1 week ago by nmrao with tags parse
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def xml = """<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="schemas.xmlsoap.org/soap/envelope/">
   <s:Body xmlns:xsd="w3.org/2001/XMLSchema" xmlns:xsi="w3.org/2001/XMLSchema-instance">
      <NDCIssueTKTResponse xmlns="TKT.svc">
         <NDCIssueTKTResult>
            <err xmlns="web2200/webservices/">
               <code>11000011</code>
               <description>FBA ERROR: incorrect quantity.</description>
               <level>200</level>
            </err>
         </NDCIssueTKTResult>
      </NDCIssueTKTResponse>
   </s:Body>

</s:Envelope>"""
def pXml = new XmlSlurper().parseText(xml)

def expectedDescription = 'FBA ERROR: incorrect quantity.'
def actualDescription = pXml.'**'.find {it.name() == 'description'}
assert actualDescription == expectedDescription, 'Description does not match'
def expectedCode = 11000011
def actualCode = pXml.'**'.find {it.name() == 'code'}
assert actualCode == expectedCode, 'Code does not match'