CreateDocumentType method: XmlDoc class

Syntax

CreateDocumentType(Name, PublicID, SystemID)

Description

Use the CreateDocumentType method to create the document type declaration (a document type node) in the XmlDoc.

You can specify only one document type node for an XmlDoc.

You need to create a document type node only if you have a document type definition (DTD). You don't need to specify a document type declaration in your XML. Generally, the DTD file is used for validating the XML.

If you do specify this type of node when creating an XmlDoc in PeopleCode, you must specify it immediately following the creation statement. Then, you must specify the document type when you create the root node. This means your code should start with the CreateXmlDoc function, creating the XmlDoc object, then use the CreateDocumentType method, followed by the CreateDocumentElement method, creating the root node.

Parameters

Parameter Description

Name

Specify the name of the document type declaration as a string.

PublicID

Specify the public ID of the document type declaration as a string.

SystemID

Specify the system ID of the document type declaration as a string.

Returns

A reference to an XmlNode object representing the document type element.

Example

The following example creates a document type declaration using the DTD named "Personal".

Local XmlDoc &inXMLDoc;
Local XmlNode &docTypeNode;
Local XmlNode &rootNode;

&inXMLDoc = CreateXmlDoc("");
&docTypeNode = &inXMLDoc.CreateDocumentType("Personal", "", "Personal.dtd");
&rootNode = &inXMLDoc.CreateDocumentElement("root", "", &docTypeNode);

This produces the following XML:

<?xml version="1.0"?>
<!DOCTYPE Personal SYSTEM "Personal.dtd">
<root/>

Considerations Using Public and System IDs

You can specify both a public and a system ID. However, if you want to use a system ID only, you must specify a Null string ("") for the public ID. To use a public ID only, you must specify a Null string ("") for the system ID. If the system ID and public ID are both Null (""), then the document type is considered as system.

To use the Personal.dtd as a system ID, you must use the following code:

&DocType = &MyDoc.CreateDocumentType("Personal", "", "Personal.dtd");

This produces the XML:

<!DOCTYPE Personal SYSTEM "Personal.dtd">

To use the Personal.dtd as a public ID, you must use the following code:

&DocType = &MyDoc.CreateDocumentType("Personal", "Personal.dtd", "");

This produces the XML:

<!DOCTYPE Personal PUBLIC "Personal.dtd">