XML DOM - Attributes
-
When using DOM to process an XML file, I need to get hold of the attributes when present. Now I can get hold of them if I know there names, but what about when I do not know the attribute names?
Set objAttributes = objDOMNode.Attributes 'check that there are attributes. If objAttributes.length > 0 Then 'we know that we've named our id reference as ''PERSONID', therefore tell the NameNodeListMap to get 'this node by using the getNamedItem method Set objAttributeNode = objAttributes.getNamedItem("PERSONID") 'store this value in the tag of the treeview tvwElement.Tag = objAttributeNode.nodeValue End If
The above code is OK for when you know the attribute name, but its the case when you dont know the number and names. Any suggests please. -
When using DOM to process an XML file, I need to get hold of the attributes when present. Now I can get hold of them if I know there names, but what about when I do not know the attribute names?
Set objAttributes = objDOMNode.Attributes 'check that there are attributes. If objAttributes.length > 0 Then 'we know that we've named our id reference as ''PERSONID', therefore tell the NameNodeListMap to get 'this node by using the getNamedItem method Set objAttributeNode = objAttributes.getNamedItem("PERSONID") 'store this value in the tag of the treeview tvwElement.Tag = objAttributeNode.nodeValue End If
The above code is OK for when you know the attribute name, but its the case when you dont know the number and names. Any suggests please.You should be able to just use the collection of XMLAttributes as an array. So you code becoes something like this:
Set objAttributes = objDOMNode.Attributes If objAttributes.Length > 0 Then // this will give you the first attribute Set objAttributeNode = objAttributes(0) tvwElement.Tag = objAttributeNode.nodeValue End If
another option is to iterate through the collection of attributes and get each one of them, and append to the tree view.
Set objAttributes = objDOMNode.Attributes If objAttributes.Length > 0 Then // This will itterate through all attributes For Each objAttributeNode in objAttributes // Use the attribute here to maybe add it to the tree view cointrol Next End If
---- www.digitalGetto.com