Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. XML DOM - Attributes

XML DOM - Attributes

Scheduled Pinned Locked Moved Visual Basic
htmlxmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sweep123
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • S sweep123

      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.

      M Offline
      M Offline
      mikanu
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups