Skip to Content
0

PI 7.5 REST Receiver XPath Expression Removing Tags

Dec 28, 2016 at 04:46 PM

394

avatar image
Former Member

Hello,

I am trying to use a REST Receiver in PI 7.5 (Single Stack) to call a web service. The end point is generated based on an XML message that is created with message mapping. The document is formatted below (DispatchRequest).

In the communication channel, I am trying to use an XPath Expression to append the entire XML document to the end of a static URL. I am currently using the expression "/descendant-or-self::node()" but that results in the XML document without any tags. I would like to pass the document with the tags and values. I have tried multiple different XPath expressions with no luck... are there any possible ideas on how to pass the XML as-is at the end of the URL?

Here is the configuration currently:

Thank you for your help!

<?xml version="1.0" encoding="utf-8"?>
<DispatchRequest>
  <vendorCode>RDWY</vendorCode>
  <accountConfig>
    <siteLoginName>LOGINNAME</siteLoginName>
    <credentials>PASSWORD</credentials>
    <direction>O</direction>
  </accountConfig>
  <accountNumber/>
  <referenceNumber>123456789</referenceNumber>
  <bolNumber>123456789</bolNumber>
  <scac>RDWY</scac>
  <quoteNumber>987654321</quoteNumber>
  <createBOL>FALSE</createBOL>
  <origin>
    <address1>123 MAIN ST</address1>
    <companyName>TEST COMPANY</companyName>
    <city>ANYTOWN</city>
    <stateName>TX</stateName>
    <country>US</country>
    <postalCode>12345</postalCode>
    <phoneNumber>800-555-1212</phoneNumber>
  </origin>
  <destination>
    <address1>123 MAIN ST</address1>
    <companyName>TEST DESTINATION</companyName>
    <contactName>TEST DESTINATION</contactName>
    <city>ANYTOWN</city>
    <stateName>TX</stateName>
    <postalCode>12345</postalCode>
    <phoneNumber>800-555-5555</phoneNumber>
  </destination>
  <lineItems>
    <item>
      <code>PRD</code>
      <quantity>33</quantity>
      <weight>740</weight>
      <weightUnit>lbs</weightUnit>
      <freightClass>100.0</freightClass>
      <description>MARKERBOARD</description>
      <hazmat>false</hazmat>
      <pieces>122</pieces>
      <stackable>FALSE</stackable>
    </item>
    <item>
      <code>PRD</code>
      <quantity>3</quantity>
      <weight>118</weight>
      <weightUnit>lbs</weightUnit>
      <freightClass>65.0</freightClass>
      <description>GLASS-CLEAR</description>
      <hazmat>false</hazmat>
      <pieces>5</pieces>
      <stackable>FALSE</stackable>
    </item>
  </lineItems>
  <dockCloseTime>23:59</dockCloseTime>
  <billTo>
    <address1>321 Primary Rd</address1>
    <companyName>BILL TO COMPANY</companyName>
    <city>NEW YORK</city>
    <stateName>NY</stateName>
    <country>US</country>
    <postalCode>10001</postalCode>
    <phoneNumber>800-555-1212</phoneNumber>
  </billTo>
  <pickupDateTime>2016-12-05T14:59:00Z</pickupDateTime>
  <deliveryDateTime>2016-12-08T21:29:00Z</deliveryDateTime>
  <pickupPhone>616-555-5555</pickupPhone>
  <pickupContactCompany>PickUp Company Name</pickupContactCompany>
  <deliveryContactPhone>800-555-5555</deliveryContactPhone>
  <emailBOLShip>false</emailBOLShip>
  <emailNotifyShip>false</emailNotifyShip>
  <emailApptShip>false</emailApptShip>
  <emailDelivShip>false</emailDelivShip>
  <emailBOLCons>false</emailBOLCons>
  <emailNotifyCons>false</emailNotifyCons>
  <emailApptCons>false</emailApptCons>
  <emailDelivCons>false</emailDelivCons>
  <emailConfirm>false</emailConfirm>
  <pickupStartTime>21:30</pickupStartTime>
  <pickupEndTime>21:30</pickupEndTime>
  <deliveryStartTime>2016-12-08T21:29</deliveryStartTime>
  <deliveryEndTime>2016-12-08T21:29</deliveryEndTime>
</DispatchRequest>
capture.png (26.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Evgeniy Kolmakov Dec 29, 2016 at 03:57 AM
0

Hi George!

I don't think that you can get entire XML document as string using XPath expression.

Regards, Evgeniy.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Thank you for the response, Evgeniy! Do you know if there is a way to append an entire XML document as-is (as a string) to the end of the URL? Is there another method I can use to achieve this?

Thanks,

George

0
avatar image
Former Member Dec 29, 2016 at 01:12 PM
0

Hi George,

In the mapping you can use return as XML option and send the entire XML to a target node and you can refer it in XPATH or you can use adapter specific attributes if you don't want to use any target node to store the entire XML value. Hope this helps.

Thanks,

Avinash

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Avinash!

As far as I know the length of ASMA attributes is limited. So using it to store payload contents may lead to errors in runtime:

The length of the attribute value is defined by the XI message protocol. Values can be a maximum of 200 characters long. If, for example, you assign longer values in the mapping or adapter modules then this can lead to processing errors at runtime or the values are shortened to 200 characters. This shortening can also lead to a processing error. The processing error that occurs depends on the components that access the attributes.

Regards, Evgeniy.
0
Former Member
Evgeniy Kolmakov

Hi Evgeniy,

Thank you for sharing that... luckily we were able to find how to still use the XPath expression but map it the way we needed.

Thanks again,

George

0
Former Member

Hi Avinash,

Thank you for that idea... we were able to wrap the entire XML payload in between a pair of target nodes that we used in the XPath Expression. We had to wrap the contents of the target node in CDATA, as the XPath was stripping the tags inside the node we mapped. Once we added the CDATA tags to the target node (using XSLT mapping), we were able to get the output to look exactly as we wanted!

The XSLT code I ended up using for the mapping is as follows:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">

<Payload>
<xsl:text disable-output-escaping="yes"> <![CDATA[ </xsl:text>
<xsl:copy-of select="DispatchRequest" />
<xsl:text disable-output-escaping="yes"> ]]> </xsl:text>
</Payload>
</xsl:template>
</xsl:stylesheet>

Notes:

  • <xsl:text> is used to create the CDATA tag and escapes the special characters and outputs the text between the tags
  • The CDATA is required because otherwise the XPath would parse out the DispatchRequest tags again from within the <Payload> tags
  • Use <xsl:copy-of> instead of <xsl:value-of> if you want to keep the node tags from "DispatchRequest"
  • Note the use of HTML encoding for open and close angle brackets.
  • To import this into Imported Archives in ESB, you must save the file as .XSL, not .XSLT, then zip and import it.

The XPath expression used is the same as in the original post, but now referring to the message created by the XSLT above: /descendant-or-self::node()

0