Reference - XML/Soap Parameters and Responses

TSL Ping Tree > Reference

Reference - XML/Soap Parameters and Responses

Populating XML/Soap posts and parsing XML/Soap responses both use a similar syntax for referencing parts of the XML. This article explains that syntax.

For the first part of this discussion we will use this example XML posting template:

<request>
   <affiliateid></affiliateid>
   <person>
      <ssn></ssn>
      <firstname></firstname>
      <lastname></lastname>
      <address>
         <postalcode></postalcode>
      </address>
   </person>
</request>

Since most of the values in this XML are children of the "person" node, the best XML posting root for this example would be "request.person". Then you could reference the "ssn" node by using the parameter name ".ssn" and the "postalcode" node by using the parameter name ".address.postalcode". If you use that posting root, you can reference the "affiliateid" node by using the absolute path (without a leading "." on the name) "request.affiliateid".

XML Attributes

Sometimes, lead buyers use attributes instead of node names to distinguish different values in the XML. In the bit of XML below, "ssn" is the value of a "name" attribute of a "data" node:

<request>
   <data name="ssn">123-45-6789</data>
   <data name="firstname">Fred</data>
</request>

To reference "ssn" in the above node with an attribute in TSL PingTree, you use this syntax:

   request.data!name=ssn

Note that in this example you CAN NOT set the posting root to "request.data" because you can not start a relative path with a "!" attribute delimiter. So for this example you could set the posting root to "request" and then you could reference "ssn" by using the parameter name ".data!name=ssn".

You can also have multiple attributes in a path. For example, given this XML:

<request>
   <data name="ssn">123-45-6789</data>
   <data name="firstname">Fred</data>
   <data name="address">
      <subdata name="street">Main Street</subdata>
      <subdata name="postalcode">30303</subdata>
   </data>
</request>

You can reference the postal code buy using the path:

   request.data!name=address.subdata!name=postalcode

Repeating XML Elements

You may need to populate values in a list of repeating elements. For example, given this XML:

<request>
   <ssn>123-45-6789</ssn>
   <fname>Fred</fname>
   <incomes>
      <income>
         <amount">900</amount>
         <source">job</source>
      </income>
      <income>
         <amount">800</amount>
         <source">alimony</source>
      </income>
   </incomes>
</request>

You can access the amount of the first income using either of these paths:

   request.incomes.income(0).amount
   request.incomes.income.amount

If you leave off the instance number then "(0)" is assumed. You can reference the amount of the second income using this path:

   request.incomes.income(1).amount

When populating repeating XML elements, the element must be present in the XML posting template. If you try to populate "request.incomes.income(5).amount" but that element doesn't exist in the template, you will get a configuration error.

In very rare instances, you may run into a really odd response type where a system responds with XML inside of XML. There is no good reason for doing this--it's usually the result of a junior level programmer implementing the system. TSL Ping Tree can parse this response type as long as all of the XML is properly formed and escaped. That response might look like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
  <soap:Body>
    <PostApplication_V2Response>
      <PostApplication_V2Result>
		&lt;SomeService&gt;
		&lt;Application&gt;
		&lt;Status&gt;PURCHASED&lt;/Status&gt;
		&lt;RedirectURL&gt;http://www.google.com?test=abc&amp;amp;xyz=123&lt;/RedirectURL&gt;
		&lt;/Application&gt;
		&lt;/SomeService&gt;
      </PostApplication_V2Result>
    </PostApplication_V2Response>
  </soap:Body>
</soap:Envelope>

The inner XML for this response is contained in the node soap:Envelope.soap:Body.PostApplication_V2Response.PostApplication_V2Result and looks like this when decoded:

<SomeService>
  <Application>
    <Status>PURCHASED</Status>
    <RedirectURL>http://www.google.com?test=abc&amp;xyz=123</RedirectURL>
  </Application>
</SomeService>

To access the item "Status" in the inner XML of this response use this syntax:

soap:Envelope.soap:Body.PostApplication_V2Response.>PostApplication_V2Result.SomeService.Application.Status

The ">" character at the beginning of the node signifies this node contains encoded XML.

When an interface returns this type of response, the XML may NOT be properly encoded. A possible issue when this type of response is being returned is that the junior programmer forgot to properly encode the "&" character. If they did that, TSL Ping Tree currently CAN NOT parse that response.