Unable to Extract data from xml payload with namespace

I'm unable to extract from the below response message:-

<?xml version="1.0" encoding="UTF-8"?>
<SendMessageResponse 
    xmlns="http://queue.amazonaws.com/doc/2012-11-05/"> 
  <SendMessageResult>
    <MessageId>90edbebd-880f-4334-95fb-9faf8723b963</MessageId> 
    <MD5OfMessageBody>d76ca0bbee493c268b5f17052f7ca3e4</MD5OfMessageBody> 
  </SendMessageResult>
  <ResponseMetadata>
    <RequestId>6157f8d7-0173-5179-b8a9-ae00f894193c</RequestId> 
  </ResponseMetadata> 
</SendMessageResponse>

Below is my extract message policy-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
  <DisplayName>Extract Variables-1</DisplayName>
  <Properties/> 
  <Source clearPayload="true">response</Source>
  <XMLPayload stopPayloadProcessing="false">
    <Namespaces>
      <Namespace prefix="awssqs">http://queue.amazonaws.com/doc/2012-11-05/</Namespace> 
    </Namespaces>
    <Variable name="requestId" type="string"> 
      <XPath>/awssqs:SendMessageResponse/ResponseMetadata/RequestId</XPath> 
    </Variable> 
  </XMLPayload>
</ExtractVariables>

What am I doing wrong? If the namespace is removed this policy is extracting perfectly. What should be the correct xpath for this message.

Note:- The xmlns tag is coming after SendMessageResponse

1 1 244
1 REPLY 1

Sorry about that. Using XPath with XML Namespaces is sort of tricky and you need to get everything just right. You were sooooo close.

here's what I suggest

<ExtractVariables name="Extract-Variables-1">
  <Source>response</Source>
  <XMLPayload>
    <Namespaces>
      <Namespace prefix="q">http://queue.amazonaws.com/doc/2012-11-05/</Namespace> 
    </Namespaces>
    <Variable name="requestId" type="string"> 
      <XPath>/q:SendMessageResponse/q:ResponseMetadata/q:RequestId/text()</XPath> 
    </Variable> 
  </XMLPayload>
</ExtractVariables>

Explanation:

  • On the inbound message, the xmlns with the value http://queue.amazonaws.com/doc/2012-11-05/ is defined in the SendMEssageResponse element.
  • Because this is a default namespace (it is tagged with xmlns=) , that means it applies to all untagged elements. SendMessageResponse and all its children will be in this namespace.
  • In Xpath, the prefix you use for a namespace is irrelevant. You can use whatever you like. The prefix you use in the xpath does not need to match the prefix used in the xml document (if there even is one!), though the namespaces to which the respective prefixes refer, must be exactly equal.
  • I like using short prefixes because it makes the xpath slightly less unwieldy