XmlSax incompatible with accented characters in file. Xml

BluSky76

Member
Licensed User
Longtime User
Just a single accented letter to crash the control XmlSax. If you replace the line <title> Phone library was updated - V1.10 </ title> with the line <title> Phone library was updated - V1.10à </ title> procedure returns error

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
If parser.Parents.IndexOf ("item")> -1 Then
If Name = "title" Then
Title = Text.ToString
Else if name = "link" Then
Link Text.ToString
Else If Name = "pubDate" Then
pubDate = Text.ToString
end If
end If
If Name = "item" Then
ListView1.AddSingleLine2 (Title, Link) 'add the title as the text and the link as the value
end If

the error applies to each character type: à or ì

:signOops:
Someone has a solution?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
SS-2011-12-29_09.47.29.png


As this file is not encoded in the default encoding (UTF8). You should use a TextReader and specify its encoding:
B4X:
   'parse the xml file
   Dim in As InputStream
   in = File.OpenInput(File.DirAssets, "rss.xml")
   Dim tr As TextReader
   tr.Initialize2(in, "ISO-8859-1")
   parser.Parse2(tr, "Parser")
   in.Close
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
Error compiling code

I tried yesterday with this method but I always have the following error:

Compiling code. 0.02
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 49
parser.Parse2(readXml, \
javac 1.6.0_30
src\readXml\xmlsax\main.java:276: cannot find symbol
symbol : method Parse2(java.io.Reader,java.lang.String)
location: class anywheresoftware.b4a.objects.SaxParser
_parser.Parse2((java.io.Reader)(_readxml.getObject()),"Parser");
^
1 error
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
Java compiled

I simply replaced in XmlSax.zip on the forum, with the lines:

'parse the xml file
'Dim in As InputStream
'in = File.OpenInput(File.DirAssets, "rss.xml")
'parser.Parse(in, "Parser")
'in.Close

'parse the xml file
Dim in As InputStream
in = File.OpenInput(File.DirAssets, "rss.xml")
Dim readXml As TextReader
readXml.Initialize2(in, "ISO-8859-1")
parser.Parse2(readXml, "Parser")
in.Close

May be incompatible with Java 1.6.30?
 
Last edited:
Upvote 0

BluSky76

Member
Licensed User
Longtime User
Sorry does not work. Usually error when compiling

Compiling code. 0.08
Generating R file. 0.00
Compiling generated Java code. Error
B4A line: 24
parser.Parse2(tr, \
javac 1.6.0_30
src\anywheresoftware\b4a\samples\xmlsax\main.java:249: cannot find symbol
symbol : method Parse2(java.io.Reader,java.lang.String)
location: class anywheresoftware.b4a.objects.SaxParser
_parser.Parse2((java.io.Reader)(_tr.getObject()),"Parser");
^
1 error
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
OK

It now works.

You can encode the writing?

It can decode written?

example file rss.xml
L&amp;rsquo;

original characters
L '

Thank you.
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
I did not understand what you mean.

If there are 12 rows in the listview (item) and can make sure that if I click on one that is highlighted. I tried ListView1.SingleLineLayout.Label.Enabled = false but is still selected. I would like clicking on a line that is evident only if Position is with an even number
 
Upvote 0

BluSky76

Member
Licensed User
Longtime User
http://www.w3schools.com/tags/ref_entities.asp

Erel,
using the library does not decode this XmlSax characters you enclose the link text and returns a result and not a illegibile.

XmlSax returns

&agrave;

and not

à

There is a solution to the problem?

thanks
 
Upvote 0
Top