[XML Records] Consuming REST API with XML response using XMLToRecordList
Forge component by Afonso Carvalho
Application Type
Traditional Web

Hello Guys,

          It's my first time working with API with an xml response, i have a problem in using the XMLToRecordList, i always get this error :

[1] Unable to load xml document:
at ssRezLive.RssExtensionXmlRecords.MssXmlToRecordList(HeContext heContext, String inParamXml, Object inParamRecordList, RecordList inParamXmlConfig, Boolean inParamIgnoreXMLDeclarationAndNS, String inParamAttributePrefix, IRecord inParamDefaultConfig, Boolean inParamBypassRootRecordListNode)
at ssRezLive.Actions.ActionGetSearchResults(HeContext heContext, String inParamxmlSearchHotels, String& outParamrawxml, String& outParamrawjson, STPostFindHotelsByDestinationStructure& outParamdeserializedData, RLHotelFindResponseList& outParamresult)
at ssuhi.RsseSpaceRezLive.MssGetSearchResults(HeContext heContext, String inParamxmlSearchHotels, String& outParamrawxml, String& outParamrawjson, IRecord& outParamdeserializedData, RecordList& outParamresult)
at ssuhi.Actions.ActionGetSearchResults(HeContext heContext, String inParamxmlSearchHotels, String& outParamrawxml, String& outParamrawjson, STPostFindHotelsByDestinationStructure& outParamdeserializedData, RLHotelFindResponseList& outParamresult)
at ssuhi.Flows.FlowMainFlow.ScrnTestHotelsXMLResults.Preparation(HeContext heContext)
at ssuhi.Flows.FlowMainFlow.ScrnTestHotelsXMLResults.Page_Load(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

[2] Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
   at OutSystems.NssXmlRecords.CssXmlRecords.MssXmlToRecordList(String ssXml, Object ssRecordList, RLRecordXmlConfigRecordList ssXmlConfig, Boolean ssIgnoreXMLDeclarationAndNS, String ssAttributePrefix, RCDefaultXmlConfigRecord ssDefaultConfig, Boolean ssBypassRootRecordListNode)

Also i forgot to mention that i'm using gzip to decompress the data.

Can anybody enlighten me about this error, i don't really understand its error, also my first time using this component.

Thank you and have a good day, hope somebody could help me!


-Laurence

Hello Laurence,

'Root element is missing' is an indication that there is something incorrect about the input xml structure.

If you can share a screenshot or reproduce a portion of the xml response from the API, that would speed up troubleshooting.

Regards,

AJ

Hello AJ,

Here's a sample xml response i'm getting from the API. I have to use gzip as per the API provider's requirements. Also the Response request is Form URL Encoded while the respnse format is in plain text. 


 <?xml version='1.0'?><HotelFindResponse time="2.2385439872742" ipaddress="192.168.1.1" count="2"><ArrivalDate>21/04/2021</ArrivalDate><DepartureDate>28/04/2021</DepartureDate><Currency>PHP</Currency><GuestNationality>IN</GuestNationality><SearchSessionId>16177879347391617787934</SearchSessionId><Hotels><Hotel><Id>479665</Id><Name>Al meroz hotel bangkok - the leading halal hotel</Name><Rating>5</Rating><ThumbImages>https://images.rezlive.com/th/864/479665/main.jpg</ThumbImages><Price>37095.128068781</Price><Hotelwiseroomcount>3</Hotelwiseroomcount><RoomDetails><RoomDetail><Type>Connecting Family Room, 1 King Bed, 2 Twin Bed</Type><BookingKey>MzQzNDe3MLc0NjE3tjSEc3QjPAxNDHQNdY0MjAx1DUx0Dcx1TcwtzcxMdbMB</BookingKey><Adults>2</Adults><Children>4</Children><ChildrenAges>2*3*4*5</ChildrenAges><TotalRooms>1</TotalRooms><TotalRate>37095.128068781</TotalRate><BoardBasis>Room Only</BoardBasis><RoomDescription>Free late check-out (2 hours later)-Free self parking, Free WiFi</RoomDescription><CancellationPolicy><Refundable>Yes</Refundable><TillDate>17/04/2021</TillDate></CancellationPolicy><TermsAndConditions></TermsAndConditions></RoomDetail><RoomDetail><Type>Connecting Family Room, 1 King Bed, 2 Twin Bed</Type><BookingKey>MzQzNDe3MLc0NjE3tjSEc3QjPAxNDHSNdI0MjAx1DUx0Dcx1TcwtzcxMdbMB</BookingKey><Adults>2</Adults><Children>4</Children><ChildrenAges>2*3*4*5</ChildrenAges><TotalRooms>1</TotalRooms><TotalRate>44371.984002667</TotalRate><BoardBasis>Breakfast</BoardBasis><RoomDescription>Free late check-out (2 hours later)-Free self parking, Free WiFi</RoomDescription><CancellationPolicy><Refundable>Yes</Refundable><TillDate>17/04/2021</TillDate></CancellationPolicy><TermsAndConditions></TermsAndConditions></RoomDetail><RoomDetail><Type>Connecting Family Room, 1 King Bed, 2 Twin Bed</Type><BookingKey>MzQzNDe3MLc0NjE3tjSEc3QjPAxNDHQNdI0MjAx1DUx0Dcx1TcwtzcxMdbMB</BookingKey><Adults>2</Adults><Children>4</Children><ChildrenAges>2*3*4*5</ChildrenAges><TotalRooms>1</TotalRooms><TotalRate>79024.722651688</TotalRate><BoardBasis>Breakfast</BoardBasis><RoomDescription>Free late check-out (2 hours later)-Free self parking, Free WiFi</RoomDescription><CancellationPolicy><Refundable>No</Refundable></CancellationPolicy><TermsAndConditions></TermsAndConditions></RoomDetail></RoomDetails></Hotel></Hotels></HotelFindResponse> 

 

Regards

-Laurence


Hi Laurence, in your XML example above you are missing the </Hotels> end tag. Regards, John.

Hi JR,

    Thanks for the correction, i must have accidentally deleted it, because the response have a lot of items therefore i reduced it to one item, i'll adjust it right away! thanks! 

Hi @laurence De Ocampo,

The xml snippet you have shared loads without issues. So I gather that your original issue is elsewhere in the response. Are you able to share the entire response text as a file here? i.e. is it test/ sample data that you can share or is it work related?

Regards

AJ

Hi AJ,

    I'm sorry that i couldn't provide you the whole file as we have  a non disclosure agreement with the provide. I think i should inform you first with what i did that lead me into this situation, first, i consumed the api, and set its response as plain text, it's request format were in Form URL Encoded, then as per the API providers docu that we should use gzip compression to get faster response from their end, so what i did was convert the api response into binary and then decompress it, and then afterwards convert it into text again and assigned the converted value into the XMLToRecordList function as its paramater for the xml, then voila, i was receiving this error i've mentioned in my post. 

Also there's another error i'm receiving, it says :


Error while decompressing: Found invalid data while decoding.

System.IO.InvalidDataException: Found invalid data while decoding.
   at System.IO.Compression.InflaterZlib.Inflate(FlushCode flushCode)
   at System.IO.Compression.InflaterZlib.ReadInflateOutput(Byte[] outputBuffer, Int32 offset, Int32 length, FlushCode flushCode, Int32& bytesRead)
   at System.IO.Compression.InflaterZlib.Inflate(Byte[] bytes, Int32 offset, Int32 length)
   at System.IO.Compression.DeflateStream.Read(Byte[] array, Int32 offset, Int32 count)
   at System.IO.Stream.InternalCopyTo(Stream destination, Int32 bufferSize)
at OutSystems.NssGZipUtil.CssGZipUtil.MssDecompress(Byte[] ssCompressedBytes, Byte[]& ssDecompressedBytes)


This was the problem i was facing, if you won't mind, i'd like to ask, what was the ideal response data type for an xml return that could be use for gzip? let's say i am getting a plain text, and if i converted it into binary, is there any possible problem that may arise, forgive that this was my first time handling API with xml, i usually deal with JSON.

Thank you and appreciate your response!





Hi @laurence De Ocampo,

Thank you for sharing more details.

If the API response is already in plain text, and an xml, then please feed it directly to XMLRecords as input.

Decompression with gzip is only needed if the input is a compressed binary. Converting text to binary is still uncompressed, so decompressing it with gzip is not necessary, and will throw the "Found invalid data while decoding" error, which you are encountering.

Hope this solves it,

Regards,

AJ

Hi @=AJ= 

     I see, so that's how it works, thanks for the reply. appreciate it!


- laurence

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