When I walk through this XML with an XMLNodeList, I can get each node fine. However, when I come to this statement:
dim myNode as XMLNode = nodelist.item(i)
dim myTag as string = myNode.GetAttribute("tag")
myTag is always returned as an empty string!
I’m watching this in the debugger; I can see the node, and myNode.ToString() shows me that the attribute is there. But GetAttribute doesn’t get it.
I’ve also tried using GetAttributeNode, which returns Nil. On the off chance that an attribute name of “tag” is somehow reserved, I changed it, but no joy.
I should note that this is happening inside an object that’s running in a XojoScript context. If I take the exact same code and run it without being called from XojoScript, it works as expected.
And I know that XojoScript doesn’t support objects; this code is inside an object that’s part of the XojoScript context.
What the @#$! is going on here? Any help is appreciated.
Then look at both myNode and foo in the debugger, it says that the AttributeCount for myNode is 6, but the AttributeCount for foo is 4. If I clone a node, shouldn’t it, umm, clone its attributes as well?
Sorry to dig this old thread, but it looks like it is still an issue:
Dim node As XmlNode
Dim nodes As XmlNodeList
Dim xml As New XmlDocument
xml.LoadXml( file )
nodes = xml.XQL( "//item" )
For i As Integer = 0 To nodes.Length - 1
node = nodes.Item( i )
Dim id As Integer = Val( node.GetAttribute( "id" ))
Dim name As String = node.GetAttribute( "id" )
Next i
id contains 1, 2, 3 etc. as expected, but name always returns an empty string (note it is the same attribute).