Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
set objXMLDOMNamedNodeMap = objDOMDocument.attributes
Remark
For more information on attributes, see chapter 2, "XML
boot camp."
This property returns an XMLDOMNamedNodeMap object, which contains a collection of
the attributes for this Node. The XMLDOMNamedNodeMap is an XML
interface specifically designed for working with attributes.
Example
A common practice is to use attributes to store the ID (using
the ID attribute type) from a database, which is declared in the
DTD as:
<!ELEMENT PERSON ( NAME, ADDRESS, TEL, FAX, EMAIL )
>
<!ATTLIST PERSON PERSONID ID #REQUIRED>
¬ Declaring our Person element will contain the following
elements (tags).
The person element has an ID attribute called
"PERSONID," which is always required.
¬ In our XML example, this attribute is used as
follows:
¬ In the following example in VB, we are busy populating
the TreeView with data from a DOMDocument. We then want to store
the PERSONID attribute in the tag property of the TreeView
Node:
'the element Node is holding the id attribute that we
want
'to store in the tag, as an identity reference. We
'therefore need to get hold of this Node to get its
value
Set objAttributes = objNode.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
¬ Get the attributes from the current Node (PERSON
Node).
¬ getNamedItem only returns a single Node (IXMLDOMNode),
because we have to specify that it must return the
"PERSONID" attribute, of which there can only be one
per element.
¬ Read the sections on getNamedItem(), setNamedItem(), and
nextNode() further in this chapter to learn more about working
with attributes in the DOMDocument.
This manuscript is an abridged version of a chapter from the
Manning
Publications book XMLProgramming with VB and ASP. This chapter
looks at the Microsoft DOM objects. NOTE: Most images have been
removed to increase speed and many of the code comments have also
been removed for presentation. Please purchase the book to enjoy
the full experience of all the chapters with images and code
comments!