views:

236

answers:

1

I am writing a business app in Flex that uses web services to communicate with a middle tier. The web services accept and return messages in XML format. In many cases, I need to be able to allow the user to type something like the following into a field in the app, which in turn will be added as an element in an XML payload bound for a SOAP web service (without the quotes):

"account balance < 1000"

The Flex parser chokes when trying to serialize an element with this in the Text node (e.g., account balance < 1000. So I need some way to encode the "<" to "<" prior to doing the XML serialization. In addition, I would prefer a generic way to do this, such as with an attribute on the service declaration, since I have over 40 services that must support this kind of input. Any ideas?

+1  A: 

use the escape and unescape functions.

http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary199.html

Gabriel McAdams
That works okay, however, encoding the string results in the input being several times longer than the original string. The service I am calling has a maxlength constraint on the element in question and apparently the encoded string is not being decoded before evaluating the constraint. So now I am getting a schema violation error.
lje
Gabriel McAdams
Would the answer be any different if I had generated an ActionScript proxy for the web service from the WSDL? As it is, I am just creating an XML document that happens to correspond to the schema that describes the web service contract. (There's a long, long story as to why I'm doing it this way.) Seems like any reasonable web service framework would handle the encoding/decoding of reserved XML characters automatigically....
lje
That should be easy enough to test.
Gabriel McAdams