Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

IXMLDOMDocumentType

Contains information associated with the document type declaration.

[C/C++]

Example

The following C/C++ example displays the doctype name of the document.

The following document was used.

<?xml version='1.0'?>
<!DOCTYPE COLLECTION [ 
<!ELEMENT COLLECTION    (DATE? , BOOK+) >
<!ATTLIST COLLECTION
    xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes">
<!ELEMENT BOOK         (TITLE, AUTHOR, PUBLISHER) >
<!ELEMENT DATE         (#PCDATA) >
<!ELEMENT TITLE         (#PCDATA)  >
<!ELEMENT AUTHOR        (#PCDATA)  >
<!ELEMENT PUBLISHER     (#PCDATA)  >
]>
<COLLECTION
   xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <BOOK>
    <TITLE>Lover Birds</TITLE>
    <AUTHOR>Cynthia Randall</AUTHOR>
    <PUBLISHER>Lucerne Publishing</PUBLISHER>
  </BOOK>
  <BOOK>
    <TITLE>The Sundered Grail</TITLE>
    <AUTHOR>Eva Corets</AUTHOR>
    <PUBLISHER>Lucerne Publishing</PUBLISHER>
  </BOOK>
  <BOOK>
    <TITLE>Splish Splash</TITLE>
    <AUTHOR>Paula Thurman</AUTHOR>
    <PUBLISHER>Scootney</PUBLISHER>
  </BOOK>
</COLLECTION>

#import "msxml5.dll"
using namespace MSXML2;

inline void TESTHR( HRESULT _hr ) 
   { if FAILED(_hr) throw(_hr); }

This is the C/C++ sample:

void XMLDOMDocumentTypeSample()
{
   try
   {
      IXMLDOMDocumentPtr docPtr;

      //init
      TESTHR(CoInitialize(NULL)); 
      TESTHR(docPtr.CreateInstance(_T("Msxml2.DOMDocument.5.0")));

      // Load a document.
      _variant_t varXml(_T("D:\\xmlSample\\xmlTest\\book1.xml"));
      _variant_t varOut((bool)TRUE);
      varOut = docPtr->load(varXml);
      if ((bool)varOut == FALSE)
      {// Show error description - IXMLDOMParseError sample.
         IXMLDOMParseErrorPtr errPtr = docPtr->GetparseError();
      // Print error details.
      }
      else
      {
         IXMLDOMDocumentTypePtr docTypPtr = docPtr->doctype;
         if (docTypPtr)
         {
            _bstr_t bstrTyp(docTypPtr->name);
            _tprintf(_T("Document type name = %s\n"), (TCHAR*)bstrTyp);
         }
            }
   }
   catch (_com_error &e)
   {
      _tprintf(_T("Error:\n"));
      _tprintf(_T("Code = %08lx\n"), e.Error());
      _tprintf(_T("Code meaning = %s\n"), (TCHAR*) e.ErrorMessage());
      _tprintf(_T("Source = %s\n"), (TCHAR*) e.Source());
      _tprintf(_T("Error Description = %s\n"), (TCHAR*) e.Description());
   }
      catch(...)
   {
      _tprintf(_T("Unknown error!"));
   }
   CoUninitialize();
}

Remarks

Each DOMDocument includes a doctype that identifies the document's IXMLDOMDocumentType. The IXMLDOMDocumentType provides access to the list of entities and notations defined for the document.

Versioning

MSXML 2.0 and later

Requirements

Implementation: msxml5.dll, msxml2.lib

[C/C++]

Header and IDL files: msxml2.h, msxml2.idl

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

doctype Property | DOMDocument | IXMLDOMDocumentType Members