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)