Groovy web console

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

parse xml and assert

Published 6 months 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="">
   <s:Body xmlns:xsd="" xmlns:xsi="">
      <NDCIssueTKTResponse xmlns="TKT.svc">
            <err xmlns="web2200/webservices/">
               <description>FBA ERROR: incorrect quantity.</description>

def pXml = new XmlSlurper().parseText(xml)

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