BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XML DOM
The DOM Property: async
The DOM Property: DOM object properties
The DOM Method: transformNodeToObject()
The DOM Method: transformNode()
The DOM Method: setNamedItem()
The DOM Method: setAttributeNode()
The DOM Method: setAttribute()
The DOM Method: send()
The DOM Method: selectSingleNode()
The DOM Method: selectNodes()
The DOM Method: save()
The DOM Method: reset()
The DOM Method: replaceChild()
The DOM Method: removeNamedItem()
The DOM Method: removeChild()
The DOM Method: removeAttributeNode()
The DOM Method: removeAttribute()
The DOM Method: nodeFromID()
The DOM Method: nextNode()
The DOM Method: loadXML()
<< XHTML
XmlSerializer >>

By :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.
First posted :03/24/2008
Times viewed :2412

 

Attributes

Is a member of: DOMDocument
XMLDOMNode
XMLDOMAttribute
XMLDOMCDATASection
XMLDOMComment
XMLDOMDocumentFragment
XMLDOMDocumentType
XMLDOMElement
XMLDOMEntity
XMLDOMEntityReference
XMLDOMNotation
XMLDOMProcessingInstruction
XMLDOMText
XTLRuntime

Syntax

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:

<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."

¬ 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 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!


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




swimming pool contractor
chicago web site design
halloween masks
Web Hosting
help desk support
Christian Dior sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP