[XML Records] XML with no isolated parent node for its children
Question
Forge component by Afonso Carvalho
Application Type
Service

I am consuming a REST Service that outputs the following XML:

<?xml version="1.0" encoding="UTF-8"?>

<response>

  <!-- A set of n result elements, where each result element is complex element with its own hierarchy -->

  <result>...</result>

  <result>...</result>

  <result>...</result>

  <!-- One optional error element, containing 2 different child elements with values-->

  <error><detail/><message/></error>

  <!-- One status element, containing a value -->

  <status></status>

</response>

ServiceStudio has generated a nested set of structures for the response with the initial consumption of this REST service specifying JSON output.  The JSON however failed in real life due to this service returning an given attribute as a string sometimes and at other times as complex object.  Switching the context to XML generated an output where at all attributes are outputted as dedicated elements.

I am failing with the XmlToRecordList on the response element not being mapped correctly.  The response element and its lack of a results parent is confusing me.

Is it possible to use XmlToRecordList on this XML and if so what is the needed pattern for the parent structure?

Also do complex elements that are singletons need to always wrapped in a record, record list, or not at all (result & error elements from this example)?  The examples and documentation where confusing to me around this, but it perhaps it would be more clear if I was able to map the parent element successfully and then run into a a series of secondary mapping errors on the child elements.

thanks

erik

Solution

Hello @erik berg 

The structure you will need is as shown below:

Note: The response attribute will hold a List of results

The local variable you will need to hold the response you get from the XmlToRecordList widget would be:

I hope this solves it,

Regards,

AJ

Thank you for the response, as with it I was get past my initial error.  Notes for future self and others:

1.  There is no need to make Records;  Structures work fine.  This was one of my areas of confusion from the examples and documentation as I thought a record wrapper was required.

2.  The name parent structure used in the xml hierarchy must match the xml root element name exactly.  This was the reason for the my parsing error as all my structures were prefixed with Service Name that was being called.




Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.