xmlsax parsing problem

joe2236

Member
Licensed User
Longtime User
hi,

i am using the xmlsax 1.00 lib and having the following problem

my test xml generated with php

B4X:
<?php
  header("Content-Type: text/xml; charset=UTF-8");
  echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
  echo("<msgs>");
  echo("<text>".utf8_encode('äüöß')."</text>");
  echo("</msgs>");
?>

does create the following error in b4a

B4X:
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 61: unclosed token

i have traced this - this error only exists if i use non ascii chars.

when using ascii chars in the xml parsing works like expected.

any suggestions erel

:confused: joe
 
Last edited:

joe2236

Member
Licensed User
Longtime User
hi erel

attached the xml file (renamed to txt because of forum xml file upload not allowed)

greetings
joe
 

Attachments

  • test.txt
    72 bytes · Views: 286

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'm not getting any error with this code:
B4X:
Sub Process_Globals
    Dim parser As SaxParser
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
    parser.Initialize
    
    parser.Parse(File.OpenInput(File.DirAssets, "test.txt"), "parser")
End Sub
Sub parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
    Log(uri)
    Log(name)
End Sub
Sub parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    Log(uri)
    Log(name)
    Log(text)
End Sub
 

joe2236

Member
Licensed User
Longtime User
ah found the problem

im getting the xml data from http

old code was
B4X:
Dim ret As String
Dim i As InputStream

ret=Response.GetString("UTF-8")
i.InitializeFromBytesArray(ret.GetBytes("UTF-8"),0,ret.Length)
parser.Initialize      
parser.Parse(i, "Parser")

new code now has no problems
B4X:
Dim ret As String
Dim i As InputStream

ret=Response.GetString("UTF-8")
i.InitializeFromBytesArray(ret.GetBytes("UTF-8"),0,ret.GetBytes("UTF-8").Length)
parser.Initialize      
parser.Parse(i, "Parser")

thanks and sorry for this - still learning

:sign0060: joe
 
Top