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