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"?>
+61xxxxxxxxxxD370532E-xxxx-41B9-xxxx-37BCF1B2C9520000Success0.0770<currency_symbol>$</currency_symbol><currency_type>AUD</currency_type>

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

  try
    rd.LoadXml(source)
  catch e as XmlException
    msgBox "Could not load XML from source"
    return 
  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>
    
  next
  return 

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.

Regards,
Tony Barry
Sydney

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.
Regards,
Tony Barry
Sydney

    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.