BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XML DOM
The DOM Property: data
The DOM Property: childNodes
The DOM Property: Attributes
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()
<< 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 :1480

 

docType

Is a member of:
XML DOM Document

Syntax

set objXMLDOMNode = objXMLDOMNode.docType

set objXMLDOMDocumentType = objXMLDOMNode.docType

Remark

This property is read-only.

The doctype is the DTD Node in the XML header. One problem that you may come across when using the DOMDocument is that you might like to add a DTD to your DOMDocument. However, because this property is read-only, you can't add a DTD and an error will occur.

So how does one get around adding a DTD to an XML file? You may think that you can just populate a string that will build up an XML file, which you can do. However, please read about the DOMDocument bug under the loadXML() method, which also explains a solution to this problem.

Example

The following XML code defines a DTD for the XML file:

<!DOCTYPE PEOPLE SYSTEM "http://localhost/xmlcode/people.dtd">

This VB example shows that a DocumentType object or a Node object is returned from the docType property of the DOMDocument root:

Dim objDOMDocument As DOMDocument

Dim objXMLDOMDocumentType As IXMLDOMDocumentType

Set objDOMDocument = New DOMDocument

objDOMDocument.async = False

objDOMDocument.resolveExternals = True

objDOMDocument.Load "http://localhost/xmlcode/people2.xml"

Set objXMLDOMDocumentType = objDOMDocument.doctype

Dual interfaces

What you may also have noticed in the properties syntax code example above is that the doctype property is being used to return values to two different objects. Take another look:

set objXMLDOMNode = objXMLDOMNode.docType

set objXMLDOMDocumentType = objXMLDOMNode.docType

¬ The values are being set, which means an actual object is being passed.

If objectA and objectB are two totally different objects, how then can you set objA = objC and also set objB = objC? In other words, how can you place objC into the two fundamentally different objects of objA and objB?

This is one of our first examples of an object being able to return two interfaces. The docType property evidently implements two different interfaces. One of these is applicable to objXMLDOMNode, and the other to objXMLDOMDocumentType. This is because the XMLDOMDocumentType object inherits the objXMLDOMNode object. We can have a closer look at this.

Let's have a look at the Local View window in Visual Basic. This screen appears under the Tools/Local View menu and shows the local variable details. Under the Type section, you can see that this object returns the IXMLDOMDocumentType interface and the IXMLDOMNode interface. Therefore, you can use either interface to read this Node, depending on the type of interface you choose to use (whichever properties/methods you need to work with).

However, if you look in Visual Basic's Object Browser (press the F2 key to see the object browser), you will find that this object only returns the IXMLDOMDocumentType. Figure  shows the IXMLDOMDocumentType interface in the Object Browser.

While we talk about the docType property, the attributes property of IXMDOMDocument and IXMLDOMNode returns the actual URI of the DTD.

If you look closer at the docTypes child Node property, you will find a collection of the entities for the DTD.


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
reservationless conference calls
Web Hosting
efax
D&g 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