WriteDocType

 

Writes out the <!DOCTYPE ...> declaration with the specified name and optional attributes.

Syntax

  
HRESULT WriteDocType (  
    const WCHAR * pwszName,  
    const WCHAR * pwszPublicId,  
    const WCHAR * pwszSystemId,  
    const WCHAR * pwszSubset);  

Parameters

pwszName
The name of the DOCTYPE. This parameter cannot be empty or NULL.

pwszPublicId
If non-NULL, this method writes PUBLIC "pubid" "sysid" where pubid and sysid are replaced with the value of the specified arguments. NULL indicates that the public ID is to be omitted; this is not equivalent to an empty string.

pwszSystemId
If pwszPublicId is NULL and pwszSystemId is non-NULL, the method writes SYSTEM "sysid" where sysid is replaced with the value of this argument. NULL indicates that the system ID is to be omitted; this is not equivalent to an empty string.

pwszSubset
If non-NULL, the method writes [subset] where subset is replaced with the value of this argument. If this parameter is NULL, no subset is written out. If no subset is written, the square brackets are not written either. NULL is not equivalent to an empty string; an empty string argument will cause the brackets to be written.

Remarks

The WriteDocType method does not check for invalid characters in pwszSystemId and pwszPublicId values. It also does not check for valid Document Type Definition (DTD)/XML syntax.

Note that the internal subset of the DTD has no indentation or formatting. The following code example shows how to format the DTD internal subset:

const WCHAR * name = L"Employees";  
const WCHAR * pubid = NULL;  
const WCHAR * sysid = NULL;  
const WCHAR * subset =  
L"<!ELEMENT Employees (Employee)+>\n"  
L"<!ELEMENT Employee EMPTY>\n"  
L"<!ATTLIST Employee firstname CDATA #REQUIRED>\n"  
L"<!ENTITY Company 'Microsoft'>\n";  
  
if(FAILED(hr = pWriter->WriteDocType(name, pubid, sysid, subset)))  
{  
    wprintf(L"Error, Method: WriteDocType, error is %08.8lx",hr);  
    return -1;  
}  

This code results in the following XML:

<!DOCTYPE Employees [<!ELEMENT Employees (Employee)+>  
<!ELEMENT Employee EMPTY>  
<!ATTLIST Employee firstname CDATA #REQUIRED>  
<!ENTITY Company 'Microsoft'>  
]>  

For an example of the WriteDocType method, see Write an XML Document using XmlLite.

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

IXmlWriter Methods