Title: Error loading XML string from com.HttpServiceRequest.readFormEncodedRequest Post by: Randy H. on January 03, 2024, 08:10:33 pm When using readFormEncodedRequest() to get the query of a POST "application/x-www-form-urlencoded" request, the resulting string cannot be loaded into a DOM document when there are escaped special characters.
The special characters & and = are escaped by doubling them per http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_ComHTTPServiceRequest_readFormEncodedRequest.html. -- incoming data (simplified) <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.024/cXML.dtd"> <cXML> <Message> <Manufacturer>Retail Acquisition & Development, Inc.</Manufacturer> </Message> </cXML> -- parsed define in_xmlStr string let in_xmlStr = in_context.httpServiceRequest.readFormEncodedRequest(FALSE) This results in the double && on the Manufacturer line <!DOCTYPE cXML SYSTEM "http://xml.cxml.org/schemas/cXML/1.2.024/cXML.dtd"> <cXML> <Message> <Manufacturer>Retail Acquisition && Development, Inc.</Manufacturer> </Message> </cXML> --Loading the string into a DOM document fails define docXML xml.DomDocument let docXML = xml.DomDocument.create() try call docXML.loadFromString(in_xmlStr) catch -- error handling code caught end try The caught error message is "Error calling docXML.loadfromstring" Removing the double && resolves the issue. Is there a way to do it natively without this code? let lv_buffer = base.StringBuffer.create() call lv_buffer.append(in_xmlStr) call lv_buffer.replace("&&","&",0) Title: Re: Error loading XML string from com.HttpServiceRequest.readFormEncodedRequest Post by: Reuben B. on January 05, 2024, 02:37:57 am I am wondering why you are using readFormEncodedRequest. The content is expected to be key-value tuples, separated by & and with = separating key and value. The doubling of the special characters simplifies the separation into key-value tables and then again simplifies the splitting of key from value. Once you have the value separated then as you noted you have to use replace to turn && back to & and == back to =
If the input is not key-value tuples but an XML document then I wonder if readXmlRequest() is the better option instead of readFormEncodedRequest. Reuben Title: Re: Error loading XML string from com.HttpServiceRequest.readFormEncodedRequest Post by: terro r. on February 21, 2024, 11:04:57 am The message "Error calling docXML.loadfromstring" has been recognized as an error. I question whether readXmlRequest() is a preferable choice to readFormEncodedRequest in the case where the input is an XML document rather than a key-value dataset. eggy car (https://eggycar.net)
|