B4J Question how to read this xml file?

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello everybody
can someone tell me with which library I can read the attached file, which I cannot read with the libraries (xml sax and xmlmap)

Here is example

B4X:
Dim aIS As InputStream = File.OpenInput(File.DirAssets,"county.xml")
    
    TR.Initialize(aIS)
    
'    TR.Initialize(File.OpenInput(File.DirAssets,"county.xml"))
    xml.Initialize
    xml.Parse2(TR,"Parser")

error:

Waiting for debugger to connect...
Program started.
[Fatal Error] :1:1: Il contenuto non è consentito nel prologo.
Error occurred on line: 26
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Il contenuto non è consentito nel prologo.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1239)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at anywheresoftware.b4a.objects.SaxParser.parse(SaxParser.java:80)
at anywheresoftware.b4a.objects.SaxParser.Parse2(SaxParser.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:632)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:98)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:78)
at b4j.example.main.start(main.java:38)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)




thank in advance
 

Attachments

  • county.xml
    16.6 KB · Views: 142

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
best xml library for me is this one:
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here, tested with this code:
B4X:
Sub AppStart (Args() As String)
    Dim x2m As Xml2Map
    x2m.Initialize
    Dim s As String = File.ReadString("C:\Users\H\Downloads\county.xml", "")
    Dim m As Map = x2m.Parse(s)
    Log(m.As(JSON).ToString)
End Sub
Note that the file starts with UTF8 BOM. This is a big mistake though it didn't cause any error when I test it.
You can remove the BOM character with:
B4X:
s = s.Substring(1)
 
Upvote 0
Top