Using this code:
Getting the XML file from server:
XML pharsing
XML file:
logs:
Getting the XML file from server:
B4X:
Select Job.JobName
Case "Post1"
Dim OutStream As OutputStream
OutStream = File.OpenOutput(File.DirInternal, "Global.xml", False) ' Job.Tag is read to set the Original Filename we specify earlier in the creation of the Job
File.Copy2(Job.GetInputStream,OutStream) ' save the file
OutStream.Close
in = File.OpenInput(File.DirInternal, "Global.xml")
parser.Parse(in, "Parser")
in.Close
XML pharsing
B4X:
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 = "color" Then
TitleColor = Text.ToString
End If
End If
If Name = "item" Then
clv1.AddTextItem(Title, Link) 'add the title as the text and the link as the value
End If
End Sub
XML file:
B4X:
<?xml version="1.0" encoding="windows-1255"?>
<rss version="2.0">
<channel>
<item>
<title>ששש</title>
<color>5</color>
<link>1</link>
<description>none</description>
</item>
<item>
<title>bbb</title>
<color>6</color>
<link>2</link>
<description>none</description>
</item>
</channel>
</rss>
logs:
B4X:
MainMenu, Response from server: <?xml version="1.0" encoding="windows-1255"?>
<rss version="2.0">
<channel>
<item>
<title>���</title> <--------- should be Hebrew
<color>5</color>
<link>1</link>
<description>none</description>
</item>
<item>
<title>bbb</title>
<color>6</color>
<link>2</link>
<description>none</description>
</item>
</channel>
</rss>
Error occurred on line: 103 (MainMenu)
org.apache.harmony.xml.ExpatParser$ParseException: At line 7, column 10: not well-formed (invalid token)
at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:515)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:474)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:321)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:279)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse(SaxParser.java:73)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4921)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)
** Service (starter) Destroy **
** Activity (mainmenu) Pause, UserClosed = true **
** Service (widget) Start **