XMLDOMDocumentType Object

The XMLDOMDocumentType object implements IXMLDOMDocumentType interface. The doctype property of the IXMLDOMDocument interface identifies the document's IXMLDOMDocumentType interface. The IXMLDOMDocumentType interface gets information on the document type declaration in the XML document. This interface also extends the IXMLDOMNode interface, so it has all the properties and methods of the IXMLDOMNode interface. The IXMLDOMDocumentType interface also implements the following extended properties:

Additional IXMLDOMDocumentType Properties

Name Description
entities Returns a node list containing references to the entity objects declared in the DTD
name Returns the name of the document type for the document
notations Returns a node list containing references to the notation objects in the DTD

Now that the IXMLDOMDocumentType interface contains information associated with the DTD, let's create a DTD named Books.dtd for the document using the following text:

  <!ELEMENT northwind:BOOKS  (item)>
  <!ATTLIST northwind:BOOKS  xmlns:northwind CDATA  #FIXED
  <!ENTITY % ItemElements "(title, author, price, quantity)">
  <!ENTITY copyright "&#xA9;">
  <!ELEMENT item  %ItemElements;>
  <!ELEMENT title (#PCDATA)>
  <!ATTLIST title language CDATA  #REQUIRED>
  <!ELEMENT author (#PCDATA)>
  <!ELEMENT price (#PCDATA)>
  <!ELEMENT quantity (#PCDATA)>

Notice that we declared a general entity called copyright in the above DTD, thus we need to reference this entity in the Books.xml document. We also need to add a line of code to the XML document so that it will reference the DTD:

  <?xml version="1.0" ?>
  <!DOCTYPE northwind:BOOKS SYSTEM "c:\Books.dtd">
  <northwind:BOOKS xmlns:northwind="www.northwindtraders.com/PO">
        <title language="English">Number, the Language of Science
Remember that the DTD has no ability to resolve namespaces. Thus, you must declare the elements that use the namespace with the namespace prefix and define an attribute for the namespace. The XML document, though, can resolve the namespace information.

Now let's take a look at how to use the properties of the IXMLDOMDocumentType interface in our example application. First, add another command button to the frmDOMTest form with the name cmdDocumentType and the caption Document Type. Then add the following code to the click event of this button:

  Private Sub cmdDocumentType_Click()
      Dim objDocumentType As IXMLDOMDocumentType
      Dim objXMLDoc As DOMDocument
      Set objXMLDoc = New DOMDocument
      objXMLDoc.async = False
      objXMLDoc.Load ("c:\Books.xml")
      Set objDocumentType = objXMLDoc.doctype
      Debug.Print objDocumentType.Name
      Debug.Print objDocumentType.xml
      Debug.Print objDocumentType.entities.length
      Debug.Print objDocumentType.entities.Item(0).xml
  End Sub

When you run this example and click the DocumentType button, you'll see the following output:

  <!DOCTYPE northwind:BOOKS SYSTEM "c:\Books.dtd">
  <!ENTITY copyright "">

Once again, you have created a reference to an IXMLDOMDocument interface. With this reference, you can use the doctype property to get a reference to an IXMLDOMDocumentType interface. Then you use the name and xml properties of the IXMLDOMDocumentType interface to get a node's name and its XML content. Notice that the parameter entity was not included in the entities collection.

by BrainBellupdated