Roberto P. Well-Known Member Licensed User Longtime User Aug 6, 2021 #1 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: Copy 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) Click to expand... thank in advance Attachments county.xml county.xml 16.6 KB · Views: 499
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: Copy 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) Click to expand... thank in advance
EnriqueGonzalez Expert Licensed User Longtime User Aug 6, 2021 #2 best xml library for me is this one: SimpleXML2 This is an update to the SimpleXMl library I posted here; https://www.b4x.com/android/forum/threads/simplexml.75571/#post-748743 This update now allows reading and writing of XML files. The node traversal is now done via the XmlNodes so this is a new library. Example project attached. Quick... www.b4x.com Upvote 0
best xml library for me is this one: SimpleXML2 This is an update to the SimpleXMl library I posted here; https://www.b4x.com/android/forum/threads/simplexml.75571/#post-748743 This update now allows reading and writing of XML files. The node traversal is now done via the XmlNodes so this is a new library. Example project attached. Quick... www.b4x.com
Erel B4X founder Staff member Licensed User Longtime User Aug 8, 2021 #3 Works fine here, tested with this code: Code: Copy 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: Code: Copy s = s.Substring(1) Upvote 0
Works fine here, tested with this code: Code: Copy 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: Code: Copy s = s.Substring(1)