Android Question [SOLVED] Passing XML data using executeJavascript

jchida

Member
Licensed User
Hi! I'm trying to pass a long string that contains data from a XML file (141KB) to a Javascript function:
Code:
Dim codigoJS As String = $"recibeString("${xmlData}");"$
    wvExtras.executeJavascript(codigoJS)
    Log("[" & DateTime.Time(DateTime.Now)&"] " & "Se termino de pasar datos XML a Javascript. Long:"&codigoJS.Length)
This xmlData is received using:
Code:
Sub DownloadXML(osmFile As String) As ResumableSub
    Dim j As HttpJob
    Dim Link As String=proxiServerURL & osmFile
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        xmlData=j.GetString
        Log("[" & DateTime.Time(DateTime.Now)&"] " & "Archivo OSM descargado...")
    End If
    j.Release
    Return j.Success
and in Javascript I have:
JavaScript:
function recibeString(mString) {
    try {
        console.log( " String recibido: " + mString);
    } catch (e) {
        console.log("ERROR en recibeString: " + e);
    }
}
and I receive:
B4X:
ERROR: Uncaught SyntaxError: Invalid or unexpected token en file:///android_asset/proxishopper.html (Linea: 1)
I also tried to escape my string using $xml:
B4X:
Dim codigoJS As String = $"recibeString('$xml{xmlData}');"$
But still the same. I use this method (executeJavascript()) to call another Javascript functions passing them some string parameters and work fine!
It seems to be that this method couldn't finish to ensemble the function call including my XML string (with especial characters, scaped or not)
Can you help to figure out a solution? Hope so
 
Last edited:

drgottjr

Well-Known Member
Licensed User
ERROR: Uncaught SyntaxError: Invalid or unexpected token en file:///android_asset/proxishopper.html (Linea: 1)
may we see that file?
 

jchida

Member
Licensed User
Sorry, for the long delay, but today I was reading about String multilines in Javascript and that was the solution:
JavaScript:
Dim codigoJS As String = $"xmlString=`${xmlData}`;
    recibeString(xmlString);"$
All I had to do was using backticks (``) to enclose my long string and then pass it as a parameter, like in my javaScript code
 
Top