简体   繁体   中英

Extract value from a xml with groovy

Hi so im loocking to extract all value from the Rows compenemnt and create variables with it.. here what i did till now any help will be considerable.

And here my xml file

在此处输入图像描述

def xml = row.get('HttpResponse'); def AMC = new XmlSlurper().parseText(xml); def allRecords=AMC.Table;

       List newAddressList=new ArrayList(); 
       for (int i=0; i < AMC.Columns.size(); i++){
       String Id = AMC.Table[i].Rows.Row.Id;
       String Text = AMC.Table[i].Rows.Row.Text;
       String Highlight = AMC.Table[i].Rows.Row.Highlight;
       String Cursor = AMC.Table[i].Rows.Row.Cursor;
        newAddressList.add(['Id':Id,'Text':Text,'Highlight':description,'Cursor':Cursor]);
   }    

data['AddressIndexList'] = newAddressList;`

Thanks Catalin for your answer but I resolved it this way:

def str = row.get('HttpResponse'); 
def xml = new XmlParser().parseText(str)
def id = xml.Rows[0].Row[0].@Id
def Text = xml.Rows[0].Row[0].@Text
def Highlight = xml.Rows[0].Row[0].@Highlight
def Description = xml.Rows[0].Row[0].@Description

data['id'] = id;
data['Text'] = Text;
data['Highlight'] = Highlight;
data['Description'] = Description;

But another question what should i do to create a variable with only a part of the variable id. For example Id="CA|CP|ENG|1V0-G0E" I want to separate the list.

Something like

Var x= CA
Var y= CP
....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM