Dumb question about XML parsing.

This is embarrassing. I have an XML string which comes to me as part of a network operation.

<?xml version="1.0" encoding="UTF-8"?>

I have the following code to get each “terminal” item and corresponding datum:-

  catch e as XmlException
    msgBox "Could not load XML from source"
  end try
  root = rd.FirstChild
  messages = root.FirstChild
  items = messages.FirstChild
  for i as integer = 0 to items.ChildCount - 1
    item = items.child(i).Name //provides the name properly, with no tags associated, e.g. price

    datum = items.child(i).toString // works but has tags  e.g. <price>0.0770</price>

The issue comes with the line :- datum = items.child(i).toString
This at least gets me the value associated with the item, but it is not the clean value - it has tags around it, e.g. 0.0770

datum = items.child(i).value //does not work (no text returned)
datum = items.child(i).getAttribute(item) //does not work (no text returned)

What might be the secret sauce that gets me the value associated with the item, in a clean way ?

I appreciate that the code does no recursion and might not be appropriate for other XML strings. That is understood.

Tony Barry

the contained text is a child node of the one you have

try something like

 datum = items.child(i).firstchild.toString 

an attribute would be “currency” if you had a node like

<price currency="USD">0.0770</price>

Hi Norman,
Many thanks for the thoughts. Your suspicion that the contained text was a child node was correct.
The “toString” property did not work (returned an empty string) but the “value” property did have the desired contents.
Your help is greatly appreciated.
Tony Barry

    item = items.child(i).Name
    datum = items.child(i).toString  // works but has tags around the desired data
    datum = items.child(i).GetAttribute(item)   //does not work - empty string
    datum = items.child(i).value   //does not work - empty string
    datum = items.child(i).FirstChild.ToString     //does not work - empty string
    datum = items.child(i).FirstChild.Value          //works properly

Having an XML utility can be useful in these situations. In my last XML project I used a tool called Editix http://www.editix.com.