XmlSlurper 没有 return 值
XmlSlurper doesn't return value
我正在使用 XmlSlurper 从 XML-Response 中获取值。为了便于测试,我在这里复制了对本地字符串的响应。我需要从 jobReqId 中获取值,在本例中为 506。如果我使用 println: jobReqId.name();
,我会得到正确的节点名称 (jobReqId)。如果我使用 println jobReqId
或 println jobReqId.text();
,我只会得到空字符串。有人有想法吗?
def body = """<JobApplicationAssessmentOrder>
<JobApplicationAssessmentOrder>
<jobApplication>
<JobApplication>
<applicationTemplateId>562</applicationTemplateId>
<lastModifiedDateTime>2020-05-28T11:43:47.000</lastModifiedDateTime>
<rating>-1</rating>
<source>1</source>
<agencyInfo />
<reference />
<usersSysId />
<cust_instr2 />
<cust_instr6 />
<cust_instr7 />
<timeToHire />
<currentEmployer />
<formerEmployee>false</formerEmployee>
<homePhone />
<phoneScreenDate />
<candComment />
<ownershpDate />
<firstName>Alex</firstName>
<lastModifiedByProxy />
<anonymizedDate />
<statusComments />
<applicationId>382</applicationId>
<candidateId>324</candidateId>
<dataSource>User Entered</dataSource>
<status>Open</status>
<lastName>K</lastName>
<candTypeWhenHired />
<hiredOn />
<phoneScreenDetails />
<sourceLabel>Corporate Site</sourceLabel>
<disabilityStatus />
<profileUpdated>0</profileUpdated>
<duplicateProfile>0</duplicateProfile>
<cust_SourceName />
<countryCode>DE</countryCode>
<averageRating>-1</averageRating>
<owner />
<jobReqId>506</jobReqId>
<contactEmail>alex@gmx.de</contactEmail>
<jobAppGuid />
<lastModifiedBy>USER</lastModifiedBy>
<nonApplicantStatus>Applied</nonApplicantStatus>
<resumeUploadDate />
<appStatusSetItemId>762</appStatusSetItemId>
<exportedOn />
<candConversionProcessed />
<referenceComments />
<anonymizedFlag>0</anonymizedFlag>
<referredBy />
<middleName />
<appLocale>de_DE</appLocale>
<cellPhone>2314</cellPhone>
<snapShotDate>2020-05-28T11:42:21.000</snapShotDate>
</JobApplication>
</jobApplication>
</JobApplicationAssessmentOrder>
</JobApplicationAssessmentOrder>"""
def xmlBody = new XmlSlurper().parseText(body);
def jobReqId = xmlBody.JobApplicationAssessmentOrder.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId;
println jobReqId
您的 xmlBody 与第一个 JobApplicationAssessmentOrder 节点的位置相同。
如果你这样做它会起作用:
def jobReqId = xmlBody.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId
这是一个常见的错误,为了防止它,我总是这样做:
def JobApplicationAssessmentOrder = new XmlSlurper().parseText(body)
def jobReqId = JobApplicationAssessmentOrder.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId
我正在使用 XmlSlurper 从 XML-Response 中获取值。为了便于测试,我在这里复制了对本地字符串的响应。我需要从 jobReqId 中获取值,在本例中为 506。如果我使用 println: jobReqId.name();
,我会得到正确的节点名称 (jobReqId)。如果我使用 println jobReqId
或 println jobReqId.text();
,我只会得到空字符串。有人有想法吗?
def body = """<JobApplicationAssessmentOrder>
<JobApplicationAssessmentOrder>
<jobApplication>
<JobApplication>
<applicationTemplateId>562</applicationTemplateId>
<lastModifiedDateTime>2020-05-28T11:43:47.000</lastModifiedDateTime>
<rating>-1</rating>
<source>1</source>
<agencyInfo />
<reference />
<usersSysId />
<cust_instr2 />
<cust_instr6 />
<cust_instr7 />
<timeToHire />
<currentEmployer />
<formerEmployee>false</formerEmployee>
<homePhone />
<phoneScreenDate />
<candComment />
<ownershpDate />
<firstName>Alex</firstName>
<lastModifiedByProxy />
<anonymizedDate />
<statusComments />
<applicationId>382</applicationId>
<candidateId>324</candidateId>
<dataSource>User Entered</dataSource>
<status>Open</status>
<lastName>K</lastName>
<candTypeWhenHired />
<hiredOn />
<phoneScreenDetails />
<sourceLabel>Corporate Site</sourceLabel>
<disabilityStatus />
<profileUpdated>0</profileUpdated>
<duplicateProfile>0</duplicateProfile>
<cust_SourceName />
<countryCode>DE</countryCode>
<averageRating>-1</averageRating>
<owner />
<jobReqId>506</jobReqId>
<contactEmail>alex@gmx.de</contactEmail>
<jobAppGuid />
<lastModifiedBy>USER</lastModifiedBy>
<nonApplicantStatus>Applied</nonApplicantStatus>
<resumeUploadDate />
<appStatusSetItemId>762</appStatusSetItemId>
<exportedOn />
<candConversionProcessed />
<referenceComments />
<anonymizedFlag>0</anonymizedFlag>
<referredBy />
<middleName />
<appLocale>de_DE</appLocale>
<cellPhone>2314</cellPhone>
<snapShotDate>2020-05-28T11:42:21.000</snapShotDate>
</JobApplication>
</jobApplication>
</JobApplicationAssessmentOrder>
</JobApplicationAssessmentOrder>"""
def xmlBody = new XmlSlurper().parseText(body);
def jobReqId = xmlBody.JobApplicationAssessmentOrder.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId;
println jobReqId
您的 xmlBody 与第一个 JobApplicationAssessmentOrder 节点的位置相同。 如果你这样做它会起作用:
def jobReqId = xmlBody.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId
这是一个常见的错误,为了防止它,我总是这样做:
def JobApplicationAssessmentOrder = new XmlSlurper().parseText(body)
def jobReqId = JobApplicationAssessmentOrder.JobApplicationAssessmentOrder.jobApplication.JobApplication.jobReqId