Help reading XML

spke711

Member
Joined
Nov 29, 2006
Messages
12
Programming Experience
Beginner
I'm having a problem reading the xml tags. I can read the values within the tags, but I need to read the tags themselves. Here is some sample xml:

VB.NET:
<CMS>
  <amountInput>500.00</amountInput>
  <CF74>Blue</CF74>
  <CF75>Green</CF75>
  <CF76>Red</CF76>
  <CF77>Orange</CF77>
</CMS

Each <CF> tag represents custom fields on a web form and the values within them. The problem is that the ids are appended in the tag name after 'CF'...so the id for <CF74> is 74. I need to somehow extract these numbers out of each tag. I tried getting the tags and elements into array (see code below) and extract it from there, but apparently the .getElementsByTagName() method does not accept wildcards.

Does anyone know how I can extract these id's? I can't change the XML because it is dynamically created (based on name-value pairs on the web form). Any ideas would be much appreciated!

VB.NET:
Dim x_doc As New XmlDocument
Dim SQLStr As String
Dim input As String
Dim output As String
        
input = TextBox1.Text

x_doc.LoadXml(input)
			
Dim customFields As XmlNodeList = x_doc.GetElementsByTagName("CF*")

Dim length As Integer = customFields.Count
 
Get all childnodes then you can parse the information from the node names
VB.NET:
Dim allFields As XmlNodeList = x_doc.documentelement.childnodes

It is also possible to make the CF* selection with XPath:
VB.NET:
Dim CFnodelist As Xml.XmlNodeList = x.SelectNodes("child::CMS/*[starts-with(local-name(),'CF')]")
 
Back
Top