How to read 2nd element of list of xml items returned in response using ExtractVariables policy in apigee?

非 Y 不嫁゛ 提交于 2019-12-11 09:15:26

问题


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&amp;_getpagesoffset=10&amp;_count=10&amp;_format=xml&amp;_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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!