   
Attributes
| Is a member of:
|
DOMDocument
XMLDOMNode
XMLDOMAttribute
XMLDOMCDATASection
XMLDOMComment
XMLDOMDocumentFragment
XMLDOMDocumentType
XMLDOMElement
XMLDOMEntity
XMLDOMEntityReference
XMLDOMNotation
XMLDOMProcessingInstruction
XMLDOMText
XTLRuntime
|
Syntaxset objXMLDOMNamedNodeMap = objDOMDocument.attributes
RemarkFor 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.
ExampleA 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:
<PERSON PERSONID="p1">
<NAME>Mark Wilson</NAME>
<ADDRESS>911 Somewhere Circle, Canberra, Australia</ADDRESS>
<TEL>(++612) 12345</TEL>
<FAX>(++612) 12345</FAX>
<EMAIL>markwilson@somewhere.com</EMAIL>
</PERSON>
For this element, its ID attribute equals
"p1."
'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 XML
Programming 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!
|