DB2 10.5 for Linux, UNIX, and Windows

DB2Connection.RegisterDTD Method

Registers the DTD with the database.

Namespace:
IBM.Data.DB2
Assembly:
IBM.Data.DB2 (in IBM.Data.DB2.dll)

Syntax

[Visual Basic]
Public Sub RegisterDTD(
   ByVal schema As String,
   ByVal name As String,
   ByVal systemID As String,
   ByVal publicID As String,
   ByVal dtdContent As String
) As String

[C#]
public String RegisterDTD(
   String schema,
   String name,
   String systemID,
   String publicID,
   String dtdContent
);

[C++]
public: String RegisterDTD(
   String schema,
   String name,
   String systemID,
   String publicID,
   String dtdContent
);

[JScript]
public function RegisterDTD(
   schema : String,
   name : String,
   systemID : String,
   publicID : String,
   dtdContent : String
) : String;

Parameters

schema
SQL schema name for the document type definition (DTD). This argument can have a null value, which indicates that the default SQL schema, as defined in the CURRENT SCHEMA special register, is used.
name
Name of the DTD. When a NULL value is provided for this argument, a unique value is generated and stored within the XML schema repository (XSR).
systemID
System identifier of the DTD. The system ID can be specified together with a public ID.
publicID
Public identifier of the DTD. The publicID argument accepts a NULL value and should be used only if same public identifier is also specified in the DOCTYPE declaration of the XML instance document or in an ENTITY declaration.
dtdContent
Content of the DTD.

Example

Sample HeadCount.dtd contains:
<!ELEMENT HeadCount (Name)*>
<!ELEMENT Name (Name)*>
<!ATTLIST Name First CDATA #REQUIRED>
<!ATTLIST Name Last CDATA #REQUIRED>
<!ATTLIST Name Relation (self | spouse | child) "self">
<!ENTITY MyFirst "Jeff">
<!ENTITY MyLast "Smith">
Sample HeadCount.xml contains:
<!DOCTYPE HeadCount SYSTEM "HeadCount.dtd">
<HeadCount>
	<Name First="Waldo" Last="Pepper">
		<Name First="Salt" Last="Pepper" Relation="spouse"/>
		<Name First="Red" Last="Pepper" Relation="child"/>
	</Name>
	<Name First="&MyFirst;" Last="&MyLast;">
		<Name First="Sharon" Last="&MyLast;" Relation="spouse"/>
		<Name First="Morgan" Last="&MyLast;" Relation="child"/>
		<Name First="Shelby" Last="&MyLast;" Relation="child"/>
	</Name>
</HeadCount>
The following C# code example demonstrate use of the RegisterDTD method:
using (DB2Connection conn = new DB2Connection(connStr))
{
	String dtdContent = null;
	String xmlDoc =null;

	try 
	{
		TextReader rd = new StreamReader("HeadCount.dtd");
		dtdContent = rd.ReadToEnd();

		// Register the DTD
		conn.RegisterDTD("NEWTON", "HEADCOUNTDTD", "http://dtd1", null, dtdContent);

		rd = new StreamReader("HeadCount.xml");
		xmlDoc = rd.ReadToEnd();

		// insert XML doc into a table validating it using registered DTD
		DB2Command cmd = conn.CreateCommand();
		cmd.CommandText = "insert into myXmlTable(xmlColumn) values( xmlvalidate( ? ) )";
		cmd.Parameters.Add("p1", DB2Type.Xml);
		cmd.Parameters[0].Value = xmlDoc;
		cmd.ExecuteNonQuery();

		//Drop the DTD
		conn.DropDTD("NEWTON", "HEADCOUNTDTD");
	}
	catch (Exception e)
	{
		// exception handling
	}
}

Return value

Function returns the DTD name, as supplied or as generated by DB2®.