Share via


WriteDocType (Compact 7)

3/12/2014

This method 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 equal 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 the same as 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 the same as 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 or for valid Document Type Definition (DTD)/XML syntax.

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'>
]>

See Also

Reference

IXmlWriter Methods
IXmlWriter Properties