none
Specifying the DTD for IXMLDOMDocument

    Question

  • I'm using MSXML 6 and MSXML2::IXMLDOMDocumentPtr to write out an XML document. I would like to specify the DTD (or even the XSD) schema as part of the document but I can't figure out how.

    I tried embedding the following as the top of the document

    <!DOCTYPE ReportOptionsAndOverrides SYSTEM \"ReportOptionsV1.dtd\">

    but pXMLDoc->loadXML returned an error saying DTD is not allowed. I also tried to set the pXMLDoc->validateOnParse to TRUE (it defaults to FALSE in MSXML 6), but that didn't help. I've also heard there is a ProhibitDTD property, but I can't find a way to set it.

    There is what appeared to be an excellent example of adding a schema to the pXMLDoc->schema property at http://msdn2.microsoft.com/en-us/library/ms753815.aspx but it failed when loading the DTD, and when I converted the DTD to XSD it loaded but pSchemaCache->add failed.

    I just want to specify either a DTD or an XSD schema in my document but I can't figure out how.

    Any ideas?
    Thursday, July 19, 2007 10:29 PM

Answers

All replies

  • Hi Bill,

     

    Please try

    xmlDoc.setProperty("ProhibitDTD", false);

    http://msdn2.microsoft.com/en-us/library/ms762632.aspx

     

    HTH,

    Zoya

     

    Wednesday, July 25, 2007 11:22 PM
  • I seem to be missing something here. I saw the function setProperty before, but when I compiled the code below I got the following error:

     

    error C2039: 'setProperty' : is not a member of 'MSXML2::IXMLDOMDocument'

     

    Code Snippet

    MSXML2::IXMLDOMDocumentPtr pXMLDoc;

    hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));

    pXMLDoc->setProperty("ProhibitDTD", FALSE);

     

     

    I see that setProperty is part of the Second Level DOM Properties. Do I have to cast pXMLDoc to something or query an interface to get a pointer or an object that knows how to use setProperties?

     

    Thursday, July 26, 2007 6:37 PM
  • Oops. I guess I have to create the doc as MSXML2::IXMLDOMDocument2Ptr (note the Document2). Compiles fine now. (dunno if it works yet......)

     

    Thanks for your help.

    Thursday, July 26, 2007 6:49 PM