Encode/decode string for XML transfer

SteveBee

Member
Licensed User
Longtime User
Do we have a built-in function that will handle code like this, in the attached image/zip?

(Note: I can't post the code directly, because it causes an Internal Server Error/500)

TIA
Steve
 

Attachments

  • Image1.zip
    2.6 KB · Views: 208
Last edited:

kanaida

Active Member
Licensed User
Longtime User
StringUtils has some Url Encode and Decode functions.
Just pass it the one with the funny html chars to the decoder and it becomes plain text.
Then to pass it in say an http request, encode it.

In vb.net or C# there is a way to do the same. I would avoid parsing those special chars yourself. You're going to miss some and get a crash by not using built in functionality cause there's a ton:
http://www.dotnetperls.com/encode-html-string
 
Last edited:
Upvote 0

SteveBee

Member
Licensed User
Longtime User
The XML library should decode those entities for you automatically.

Which XML library?
Do you mean the wrapper for the parser?

In view of the fact that I'm constructing/deconstructing SOAP wrappers myself, I thought I might have to pass through these encode/decode functions.
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
StringUtils has some Url Encode and Decode functions.

No, they're not the right ones.
When using encoding, they produce stuff like "....%3e+..." etc., for use in URLs.

What's required is HtmlEncoding, where "&" becomes "&"
 
Upvote 0

SteveBee

Member
Licensed User
Longtime User
In view of the fact that I'm constructing/deconstructing SOAP wrappers myself, I thought I might have to pass through these encode/decode functions.

Erel - And indeed I do..

Take an example where I'm compiling an HTTP request string, creating an HTTP request with parameters (input to sub as a Map):
B4X:
   For i = 0 To parameters.Size -1
      XML = XML & "<" & parameters.GetKeyAt(i) & ">" & parameters.GetValueAt(i) & "</" & parameters.GetKeyAt(i) & ">" 
   Next

If one of my text parameters has the value
"More & more this won't work"

Then the XML string is well screwed! <g>
 
Last edited:
Upvote 0

SteveBee

Member
Licensed User
Longtime User
The XML library takes care of decoding the string during parsing.
e]

This is *not* parsing that I'm talking about.

Including my sample text in the XML of an HTTP Request produces a "Bad Request" error. (Stands to reason that it would!)

What's needed is HtmlEncode ( as in ASP.NET Server object). Doesn't exist? Ok , I'll manage it.
 
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
StringUtils does that encoding like i said, encodes and decodes.

That's precisely what I use for making http requests where I have to send text and make sure that it's accepted properly

html encoded values have things like %3D etc... in place of regular characters.
It just looks for these special chars, and replaces them with garbled looking text, usually with a % sign in front.

are you just encoding the values or ALL of the entire request?
 
Last edited:
Upvote 0

robh

Member
Licensed User
Longtime User

Hi,

I'm also running into the same problems with ampersands in my xml request, did you solve this encoding issue in the end?

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…