B4J Question read xml files

Isac

Active Member
Licensed User
Longtime User
Good evening,

I would need to read an xml file and identify a data and read it in a label.

example: if I insert 0 in a textbox I would like to read toast in a label.

<properties>
<entry key = "0"> toast </entry>
<entry key = "1"> sandwich </entry>
<entry key = "2"> salad </entry>

Kindly does anyone have any examples?

Thanks for your attention
 

aeric

Expert
Licensed User
Longtime User
 
Upvote 0

Isac

Active Member
Licensed User
Longtime User
hi all,

<?xml version="1.0" encoding="UTF-8"?>
<!--<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">-->
<properties>
<entry key = "0"> toast </entry> <------------------------- i can't read the first line
<entry key = "1"> sandwich </entry>
<entry key = "2"> salad </entry>

when i start the program i have no errors but it indicates that xm is not initialized
I would need your help if possible :)

B4X:
ub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private ParsedData As Map
    Private Label1 As Label
   
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim xm As Xml2Map
    xm.Initialize
    ParsedData = xm.Parse(File.ReadString(File.DirAssets, "test.xml"))  
    Dim zero As Map = ParsedData.Get("0")
    Label1.Text=zero
   

End Sub
 
Upvote 0
Top