次の方法で共有


IXMLDOMDocumentType

 

Contains information associated with the document type declaration.

Example

The C/C++ example below displays the doctype name of the document. The example uses an XML resource file, books1.xml.

XML Resource file: books1.xml

<?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>  
  

C/C++ Source file: DocType.cpp

#include “msxml6.h”  
  
inline void TESTHR( HRESULT _hr )   
   { if FAILED(_hr) throw(_hr); }  
  
void XMLDOMDocumentTypeSample()  
{  
   try  
   {  
      IXMLDOMDocumentPtr docPtr;  
  
      //init  
      TESTHR(CoInitialize(NULL));   
      TESTHR(docPtr.CreateInstance(_T("Msxml2.DOMDocument.3.0")));  
  
      // Load a document.  
      _variant_t varXml(_T("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.

Requirements

Implementation:

Msxml3.dll, msxml2.lib (MSXML 3.0)

msxml6.dll, msxml6.lib (MSXML 6.0)

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

Versioning

Implemented in: MSXML 3.0, MSXML 6.0

See Also

doctype Property1
IXMLDOMDocument-DOMDocument
IXMLDOMDocumentType Members