Forum Discussion

Oct21's avatar
Oct21
Occasional Contributor
6 years ago

Getting error "content is not allowed in prolog" while parsing XML through groovy scripts

Hi 

Am using groovy script to parse the XML. Am able get all the data nodes but not able to fetch the particular which i want.

Code 

assert context.response

def getData = { data, element ->
new XmlSlurper().parseText(data).'**'.find {it.name() == element}
}

def inXmlStr = getData(context.response, 'Acknowledge').text()
log.info inXmlStr
def receiptId = getData(inXmlStr, 'ReceiptId')
log.info receiptId
context.testCase.setPropertyValue('ID', receiptId.IdValue.toString())

 

Response XML : <?xml version="1.0" encoding="utf-8"?>
<AcknowledgeCandidateRegistration majorVersionId="1" minorVersionId="0" xmlns="http://cebtalentcentral.com">
<ApplicationArea>
<CreationDateTime>2019-02-12T15:11:05.027Z</CreationDateTime>
</ApplicationArea>
<Acknowledge>
<OriginalApplicationArea>
<CreationDateTime>2019-02-12T15:11:03.470Z</CreationDateTime>
</OriginalApplicationArea>
<ReceiptId>155785</ReceiptId> // this particular id
<Status>Completed</Status>
<RejectCode>0</RejectCode>
<RejectReason />
</Acknowledge>
<DataArea>
<AssessmentOrder>
<Assessment packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="2166874" language="MULTI" stage="1" jobLevel="Graduate/University" originalTimer="00:25:00" adjustedTimer="00:25:00" />
<Report packageTag="A_VAT_Induct" name="Verify - Inductive Reasoning (2007)" orderItemRef="1698389" language="en-US" comparisonGroup="" reportFormat="Pdf" reportMedia="Link" />
<AssessmentAccess hasAssessments="true">
<Assessment stage="1">
<AssessmentCommunication>
<URI>https://integration-talentcentral-qa2.eu.shl.com/integration/ce/7d67354c372440d988d8c85dd355c48a/?rid=155785</URI>
</AssessmentCommunication>
</Assessment>
</AssessmentAccess>
</AssessmentOrder>
</DataArea>
</AcknowledgeCandidateRegistration>

 

Regards,

Oct21

No RepliesBe the first to reply