Hello,
I'm working with xml documents.
There's a bunch of <ARTNR>the number</ARTNUMBER> nodes in there.
I can get them all using an xpath expression borrowed from the
archives.
Now, how do I get only the data (the numbers) without the tags?
First make sure your xml is structured like this:
<tag>data</tag>
instead of e.g.:
<tag>
data
</tag>
Else, your function will work fine, but your listbox will fill
with blank lines instead of the data.
----------------
//declare your variables
dim nodeList as XMLNodeList
dim node as XmlNode
dim i As Integer
dim count as Integer
//load the xml file and parse it
//next, get all the <ARTNR> tags with a very simple xpath
//query
theFile = getFolderItem("H01.xml")
if theFile.Exists then
xmlDoc = new XMLDocument
xmlDoc.loadXML(theFile)
xmlDoc.PreserveWhitespace=False
nodeList = xmlDoc.xql("//ARTNR")
end if
//get the number of nodes in the nodelist for the array
count=nodeList.Length-1
//for every node, get the child node (the data)
//check if it's a text node (and not another xml tag)
//and add the value of that node to a listbox or whatever
for i= 0 to count
node=nodeList.Item(i)
node=node.Child(0)
if node.Type=XmlNodeType.TEXT_NODE then
ListBox1.AddRow(node.Value)
end if
next i
---------------
I see the value of figuring this out on my own, since
I am still learning, but at the same time I
wish RB xml was better documented.
e.g. there's no way of getting the value before checking
if it's of type text. since the xml is handwritten by me, I
know what type it is. Strange that this is so strict while
other things you can only find out because your app
crashes...
Other than that, RB is soooo much fun :-)
Koen van Hees
Les Allées de St. Genis
299 Allée Diderot
01630 St Genis Pouilly
France
tel: +33 (0)4 50 42 08 78
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>