[Gambas-user] Problem reading attributes from XML file
Markus Schatten
markus.schatten at ...2005...
Sat Feb 27 22:35:47 CET 2016
Dear friends,
I have a piece of code that was recently working, but for some reason
it stopped (using 3.5.4. currently). What I would like to do is simply
read out all attributes and their values (if they exists) from an
XmlNode. Here is what I do:
Public Sub btnLoad_Click()
Dim xml As New XmlDocument
Dim txt As String
Dialog.Filter = ["*.xml", "XML Documents"]
If Dialog.OpenFile() Then Return
txt = File.Load(Dialog.Path)
xml.FromString(txt)
parse(xml.Root)
End
Public Sub parse(node As XmlNode) As Collection
Dim child As XmlNode
Dim ret As New Collection
If node.Attributes Then
For Each child In node.Attributes
ret["@" & child.Name] = child.Value
Next
Endif
Return ret
End
The XML file I'm trying to read is:
<exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist">
<exist:collection name="/db"
created="2016-02-27T19:24:55.787+01:00" owner="SYSTEM" group="dba"
permissions="rwxr-xr-x">
<exist:collection name="apps"
created="2016-02-27T19:25:36.612+01:00" owner="SYSTEM" group="dba"
permissions="rwxr-xr-x"/>
<exist:collection name="system"
created="2016-02-27T19:24:55.792+01:00" owner="SYSTEM" group="dba"
permissions="rwxr-xr-x"/>
</exist:collection>
</exist:result>
What happens is that in the parse function on the first entry into the
for each loop the app crashes and the following message is displayed
in the console:
FATAL : tried to create a Gambas object with invalid type.
I've lost the few past hours searching for a solution, but the only
thing that I found is that the error is thrown in node.cpp from the
gb.xml source (e.g. here
https://github.com/justlostintime/gambas/blob/master/gb.xml/src/node.cpp).
What am I doing wrong? How should I get all attributes from an XmlNode?
All the best,
M.
--
Markus Schatten, PhD
Assistant professor and head of Artificial Intelligence Lab
University of Zagreb
Faculty of Organization and Informatics
Pavlinska 2, 42000 Varazdin, Croatia
http://www.foi.hr/nastavnici/schatten.markus/index.html
http://www.researchgate.net/profile/Markus_Schatten1
http://ai.foi.hr
More information about the User
mailing list