B4J Library SimpleXML

To preface this I see Erel has released a class which may help you. See here; https://www.b4x.com/android/forum/t...ple-way-to-parse-xml-documents.74848/#content

I primarily use JSON in my day job so XML is not my forte. I had to parse some simple XML files from a web service. I tried XML SAX but it was way too complicated. I tried to use the java object "toJSONObject" method but this proved unreliable especially when some items in the XML were sometimes a single item but sometimes a collection.

Anyway, I came across this library;

https://github.com/toastedcode/SimpleXML

I have ported this to a B4J Library (attached). The library uses XPath to search through XML. I found this approach much more palatable for my use.

Sample code below.

B4X:
Dim x As SimpleXMLWrapper
x.Initialize(Manifest)
          
Dim L As List
L.Initialize  

L = x.GetNodesValues("/SVCManifest/Resources/SVCResource/OnPremisePath")      
MXD = L.Get(0)
          
If MXD = "" Then MXD = "Unknown"
          
L = x.GetNodesValues("/SVCManifest/Databases/SVCDatabase/Datasets/SVCDataset/OnPremisePath")
          
For Each node As String In L
    Log(node)
Next

Not all functionality is implemented (eg its read only right now).
 

Attachments

  • SimpleXML.zip
    11.9 KB · Views: 371
Last edited:

m4.s

Member
Licensed User
Longtime User
Hello,

This is great, and is the preferred way to parse XML; coming from a Javascript development perspective.

But, it's incomplete until you can add/finish the "write" XML support - e.g. adding nodes, setting attribute values, removing nodes and attributes, etc.

Have you been able to make further progress on this B4J library project? It will surely be useful to many forum developers!
 
Top