Hi,
I am trying to extract xml values by XPATH from the below xml payload..
<sample xmlns="http://www.w3.org" xmlns:a="http://google.com/a" xmlns:b="http://google.com/b" xml:base="https://yahoo.com/"> <id>https://yahoo.com/mail</id> <title type="text">mail</title> <updated>2015-10-05T13:17:07Z</updated> <author> <name/> </author> <link href="mail" rel="self" title="mail"/> <entry> <id>https://yahoo.com/mail('0012345678')</id> <title type="text">mail('0012345678')</title> <updated>2015-10-05T13:17:07Z</updated> <category term="yahoo email" scheme="http://yahoo.com/mail"/> <link href="mail('0012345678')" rel="self" title="mail"/> <content type="application/xml"> <a:properties xmlns:a="http://http://google.com/a" xmlns:d="http://google.com/b"> <b:mail_Level_1_Code>L10332</b:mail_Level_1_Code> <b:mail_Level_2_Code>L20973</b:mail_Level_2_Code> <b:Contact_Person_First_NM>AXXX</b:Contact_Person_First_NM> <b:Contact_Person_Last_NM>AXXNXXX</b:Contact_Person_Last_NM> <b:Contact_Person_Email_ADDR>nXXmail@gmail.XXX</b:Contact_Person_Email_ADDR> <b:Additional_Notes></b:Additional_Notes> </a:properties> </content> </entry> <entry> <id>https://yahoo.com/mail('00123498886')</id> <title type="text">mail('00123498886')</title> <updated>2015-10-05T13:17:07Z</updated> <category term="yahoo email" scheme="http://yahoo.com/mail"/> <link href="mail('00123498886')" rel="self" title="mail"/> <content type="application/xml"> <a:properties xmlns:a="http://http://google.com/a" xmlns:d="http://google.com/b"> <b:mail_Level_1_Code>L10000</b:mail_Level_1_Code> <b:mail_Level_2_Code>L22222</b:mail_Level_2_Code> <b:Contact_Person_First_NM>bxxx</b:Contact_Person_First_NM> <b:Contact_Person_Last_NM>bxxnxx</b:Contact_Person_Last_NM> <b:Contact_Person_Email_ADDR>axxmail@gmail.XXX</b:Contact_Person_Email_ADDR> <b:Additional_Notes></b:Additional_Notes> </a:properties> </content> </entry> </sample>
I need to extract the values of below properties from the above payload.
<b:Contact_Person_First_NM>bxxx</b:Contact_Person_First_NM> <b:Contact_Person_Last_NM>bxxnxx</b:Contact_Person_Last_NM> <b:Contact_Person_Email_ADDR>axxmail@gmail.XXX</b:Contact_Person_Email_ADDR>
Kindly suggest with answers.Thanks in advance
@sumiya , Welcome to Apigee Community. Just a small tip while posting questions, You can indent code using CODE button in text editor. I have done same for now, moving forward you can use same. Thanks
HI anil,
Thanks for your suggestion .sure,I will follow your suggestion by going forward.
Hi @sumiya,
You can do use an extract variable like so to just grab the values:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="ExtractXMLStuff"> <DisplayName>ExtractXMLStuff</DisplayName> <Source>response</Source> <XMLPayload stopPayloadProcessing="false"> <Variable name="first" type="nodeset"> <XPath>//*[name()='b:Contact_Person_First_NM']</XPath> </Variable> <Variable name="last" type="nodeset"> <XPath>//*[name()='b:Contact_Person_Last_NM']</XPath> </Variable> <Variable name="email" type="nodeset"> <XPath>//*[name()='b:Contact_Person_Email_ADDR']</XPath> </Variable> </XMLPayload> </ExtractVariables>
But what this actually does is perform 3 separate xpath queries and then populate variables first, last and email respectively.
If this is enough for you then problem solved 🙂 If you'd like to do more, however, then you may need to use a little javascript.
Hope this helps,
/geir
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |