convert a "simple" XML to a database table

hi all, I thought this was going to be simple, but I have to admit that the XML processing with XOJO is not so easy as I thouhgt it would be.

I have a rather simple XML that looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> <rmx version="1.4"> <header changedate="20150108"/> <body> <mu> <prop type="alt">7723-23</prop> <muv xml:country="be"> <hex>8B6</hex> </muv> <muv xml:country="de"> <hex>D16</hex> </muv> </mu> <mu> <prop type="alt">7723-24</prop> <muv xml:country="be"> <hex>1590</hex> </muv> <muv xml:country="de"> <hex>8B3</hex> </muv> </mu> </body> </rmx>

I want to loop throught this XML and capture per MU the HEX value for all the COUNTRY’s listed. In one XML I have many MU’s and in one MU I have one property but many MUV’s.

The problem is not how to put this in a DB but how to extract this info from the XML. I tried to work on the XML sample, but I fail to extract what I need.
Could somebody help me? I think even untested air-code would already help me at this point.



This is the best I came up with:

[code] Dim xml As New XmlDocument
xml.LoadXml(SampleXML) // that is the document listed here above

Dim nodes As XmlNodeList
Dim node As XmlNode
Dim an As XmlAttribute
Dim hex as string

nodes = xml.XQL("/rmx/body/mu/muv")

For i As Integer = 0 To nodes.Length-1
node = nodes.Item(i)

an = node.GetAttributeNode("xml:country")
hex = node.Child( 0 ).FirstChild.Value
MsgBox(an.Value + EndOfLine + hex)

node = node.NextSibling


Is this the right way to do this?

Have you looked at this project: Examples/Text/XMLExample?

Run it and select your XML file and it will show you the contents in a hierarchical ListBox. You can check out the code to see how it find and displays everything.

XML in Xojo is no more difficult than in any other language. You have to deal with the hierarchy/tree structure either way. As Gert demonstrates, XQL is your friend.

Paul, yes I worked on that to start with, but I found it quite hard to understand. I tested it on a lot of XML files, and it’s always working. I’m impressed, but I did not understand how it is done.

Tim, thanks for confirming XQL is the way forward. There is not a lot of info on XQL in the documentation, but it is very similar to XPath.

thank you both,