This site has been taken over by the staff of www.ASPDeveloper.Net

Please report errors to suggest@aspdeveloper.net

BizTalk Utilities CV ,   Jobs ,   Code library  
 
 

Microsoft DOM Objects Reference

Download ReferenceDownload this Reference 

Previous PageTable Of ContentsIndexNext Page

docType

Is a member of:
XMLDOMDocument

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.

Previous PageTable Of ContentsIndexNext Page

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!

 

Recent Jobs

Software Specialist, Linux - Finlan
Linux Core Technical Project Manage
Graphics designer at Tanzania. Expe
Integration Specialist Needed - Wor
Virtualization Server Infrastructur

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






    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