问题
I am receiving an XML payload response target system that follows the following structure...
<feed xmlns="http://www.w3.org/2005/Atom">
<title/>
<id>7c818dcd-d66a-4273-b043-ff468b956d1b</id>
<link rel="self" href="http://fhirtest.uhn.ca/baseDstu1/Patient?address=usa"/>
<link rel="next" href="http://fhirtest.uhn.ca/baseDstu1?_getpages=943fd84d-1f93-4c97-8bba-534e944e74cf&_getpagesoffset=10&_count=10&_format=xml&_pretty=true"/>
<link rel="fhir-base" href="http://fhirtest.uhn.ca/baseDstu1"/>
</feed>
and am trying to use an Extract Variables policy to obtain the value of the href attribute of <link>
tag where attribute rel="next".
Following is the Extract variable policy i have written that extracts value of attribute href of first <link>
tag.
<ExtractVariables name="ReadLinkURLs">
<Source>response</Source>
<XMLPayload>
<Namespaces>
<Namespace prefix="patient">http://www.w3.org/2005/Atom</Namespace>
</Namespaces>
<Variable name="href" type="string">
<XPath>/patient:feed/patient:link/@href</XPath>
</Variable>
</XMLPayload>
<VariablePrefix>pagingpatient</VariablePrefix>
</ExtractVariables>
The variable 'href' is set to the string "http://fhirtest.uhn.ca/baseDstu1/Patient?address=usa", i.e the first value. Can you please suggest the changes i have to make to read the href
attribute value of that <link>
element in which rel="next"
. Thanks in advance.
回答1:
I don't know about apigee, but the XPath predicate expression to restrict <link>
elements to only those having rel
attribute value equals "next"
is [@rel='next']
. So, your entire XPath expression should look about like this :
<XPath>/patient:feed/patient:link[@rel='next']/@href</XPath>
来源:https://stackoverflow.com/questions/31717179/how-to-read-2nd-element-of-list-of-xml-items-returned-in-response-using-extractv