XML Help - reading an Attribute name

Hi guys,
I’m sure this is simple, but I’m new to XML. I’m trying to read XML and can’t seem to find a way to 'read the name of an attribute i.e…

<?xml version="1.0" encoding="UTF-8"?> <Sen Type="IMFree"> <EStr>ERX Message! Free config!</EStr> <RKorr X="0" Y="0" Z="0" A="0" B="0" C="0"/> <AKorr A1="0" A2="0" A3="0" A4="0" A5="0" A6="0"/> <EKorr E1="0.0000" E2="0.0000" E3="0.0000" E4="0.0000" E5="0.0000" E6="0.0000"/> <Tech T21="1.09" T22="2.08" T23="3.07" T24="4.06" T25="5.05" T26="6.04" T27="7.03" T28="8.02" T29="9.01" T210="10.00"/> <DiO>125</DiO> <IPOC>4219637576</IPOC> </Sen>

How do I read the names X, Y, A1, T21 etc? I can get their values if I know there names, but can’t seem to find the correct method to get the names of the variables themselves?

Thanks again,
James

Looks like there is no Attribute by number function, but you can interrogate the children of a node and see what types they are.

From the help:

[code]Dim xml As New XmlDocument(kXML)

Dim n As XmlNode = xml.DocumentElement.FirstChild

If n <> Nil Then
Dim nodeType As String

Select Case n.Type
Case XmlNodeType.ELEMENT_NODE
nodeType = “Element”
Case XmlNodeType.ATTRIBUTE_NODE
nodeType = “Attribute”
Case XmlNodeType.TEXT_NODE
nodeType = “Text”
Case XmlNodeType.CDATA_SECTION_NODE
nodeType = “CData Section”
Case XmlNodeType.ENTITY_REFERENCE_NODE
nodeType = “Entity Reference”
Case XmlNodeType.ENTITY_NODE
nodeType = “Entity”
Case XmlNodeType.PROCESSING_INSTRUCTION_NODE
nodeType = “Processing Instruction”
Case XmlNodeType.COMMENT_NODE
nodeType = “Comment”
Case XmlNodeType.DOCUMENT_NODE
nodeType = “Document”
Case XmlNodeType.DOCUMENT_TYPE_NODE
nodeType = “Document Type”
Case XmlNodeType.DOCUMENT_FRAGMENT_NODE
nodeType = “Document Fragment”
Case XmlNodeType.NOTATION_NODE
nodeType = “Notation”
Case XmlNodeType.OTHER_NODE
nodeType = “Other”
Else
nodeType = “Unknown”
End Select[/code]

MsgBox("Type: " + nodeType)
End If

Look at GetAttributeNode(Index as Integer). For your example, try this:

  dim f as FolderItem = SpecialFolder.Desktop.Child("test.xml") //a file with your xml in it  
  Dim xml As New XmlDocument(f)

  Dim n As XmlNode = xml.DocumentElement.Child(2)
  dim an as XmlAttribute
  
  for i as Integer = 0 to n.AttributeCount - 1
    an = n.GetAttributeNode(i)
    System.DebugLog an.Name + ": " + an.Value
  next

Thanks very much gents!

This solved my problem. I’d tried GetAttributeNode, but wasn’t setting the child index correctly.

Thanks again,
James