[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: posting ampersand in xml



Sender: Scott Klement <sk@xxxxxxxxxxxxxxxx>


We run a RPG program that constructs an xml string from DB2/400 data. This xml string is then passed to a program that executes the http_url_post_raw function posting the string to a java servlet. This works fine unless the string contains an ampersand character. For example, the RPG program (using http_url_post_raw) passes this xml string to the servlet correctly: "<data><id>1234</id><company>SMITH INC </company></data>". However if the string is equal to "<data><id>3456</id><company>SMITH & WESSON</company></data>" then the program only sends the first 34 characters to the servlet.

Are you using HTTPAPI's encoder routines, or are you just passing the string as-is to http_url_post_raw()?


If you're just passing the string directly to http_url_post_raw(), then HTTPAPI doesn't do any sort of encoding. The data is translated to ASCII then copied byte-by-byte to the Web server.

It pays absolutely no attention to what the bytes contain. Whatever you tell it to send, it'll send.

However, the ampersand character does have a special meaning, both in a URL encoded document and in an XML document. So, it's possible that the Web server is trying to interpret the character as an XML entity, or a variable separator, or something like that. This has nothing to do with HTTPAPI, though. HTTPAPI assumes that you know what you're doing, and just sends whatever you ask it to send.


If the xml string contains an ampersand sign then the string is truncated at the ampersand sign. This truncation causes a problem on the web side because the XML string is incomplete. Our first impression is that the utility's http_url_post_raw is encoding the spaces in the string correctly but not the ampersand sign.

http_url_post_raw does not encode the data AT ALL aside from translating it from EBCDIC to ASCII. (and If you call http_url_post_raw2, it won't even do that!)


If you want the data to be encoded, you have to call an encoder routine FIRST, then pass the already encoded data to HTTP_url_post_raw().

HTTPAPI doesn't care what your data is, only where it's located in memory and how long it is. It doesn't try to read or interpret it, it just copies it from memory to the network.


We have seen some literature that says the ampersand needs to be replaced with "&amp;" - we have tried that in the program that constructs the xml string but that has not worked.

That might matter to an XML parser, but it won't matter to HTTPAPI or to the HTTP protocol.
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubsribe from the list send mail
to majordomo@xxxxxxxxxxxxx with the body: unsubscribe ftpapi mymailaddr
-----------------------------------------------------------------------