Awesome
17 years agoFrequent Contributor
parsing xml with ':'
hi all,
i'm having some trouble with the code below, thanks in advance for your help!
TASK: i want grab the values in each element from 6 Records in a response.
the_node, returns all 6 Records
params.each {params.toString()}, returns each record
PROBLEM:
the_node.Record['@GiftId'], returns null.
I think it's because in the xml it's
so i need to do something like (these don't work):
the_node.Record['@ens:GiftId'] or the_node.Record.ens:GiftId
How do I access the element when there is a colon : in the name?
---------------snippet of the code------------
def the_node = new groovy.util.XmlParser(false,false).parseText(response.value);
def params = the_node["soap:Body"]["QueryResponse"]["Record"]
log.info "the value is: " + the_node.Record['@ens:GiftId']
_________________________________________________
params.each {params.toString()}
-----RETURNS 1 record--------
Record[attributes={xsi:type=ens:PFG}; value=[ens:GiftId[attributes={}; value=[1002]], ens:CId[attributes={}; value=[1000]], ens:CreationDate[attributes={}; value=[2009-02-02T18:58:16Z]], ens:ModifyDate[attributes={}; value=[2009-02-02T18:58:16Z]]]]
'the_node' contains 6 of the above records
i'm having some trouble with the code below, thanks in advance for your help!
TASK: i want grab the values in each element from 6 Records in a response.
the_node, returns all 6 Records
params.each {params.toString()}, returns each record
PROBLEM:
the_node.Record['@GiftId'], returns null.
I think it's because in the xml it's
so i need to do something like (these don't work):
the_node.Record['@ens:GiftId'] or the_node.Record.ens:GiftId
How do I access the element when there is a colon : in the name?
---------------snippet of the code------------
def the_node = new groovy.util.XmlParser(false,false).parseText(response.value);
def params = the_node["soap:Body"]["QueryResponse"]["Record"]
log.info "the value is: " + the_node.Record['@ens:GiftId']
_________________________________________________
params.each {params.toString()}
-----RETURNS 1 record--------
Record[attributes={xsi:type=ens:PFG}; value=[ens:GiftId[attributes={}; value=[1002]], ens:CId[attributes={}; value=[1000]], ens:CreationDate[attributes={}; value=[2009-02-02T18:58:16Z]], ens:ModifyDate[attributes={}; value=[2009-02-02T18:58:16Z]]]]
'the_node' contains 6 of the above records