Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## INITIALIZE-DOCUMENT-TYPE( ) method

> Creates a new XML document, initializes the document based on the referenced DTD, and creates its root node.

> Return type: LOGICAL

> Applies to: X-document object handle

> Syntax
>     INITIALIZE-DOCUMENT-TYPE( namespace-uri , root-node-name , public-id ,
>     system-id )

> ``namespace-uri``

> A character expression representing the namespace Uniform Resource Identifier (URI) you want associated with the root node of the XML document. The `namespace-uri` must be unique and persistent.

> ``root-node-name``

> A character expression representing the name of the root node as defined in the XML document. If you are using namespaces and you want to associate a prefix with the namespace, you must qualify this node name with the `namespace-uri` and a colon character prefix (for example, `namespace-uri:root-node-name`). You must explicitly set the xmlns attribute on the root node.

> ``public-id``

> An optional character expression representing the public ID of the DTD. Currently, there is no way to retrieve a DTD based on a public ID.

> ``system-id``

> A required character expression representing the system ID of the DTD. This contains the path to the DTD which is either a file system path or an HTTP URL. The Progress parser uses this information to retrieve the DTD when parsing the document.

> Example

> The following example initializes an X-document with a DTD reference and adds the proper namespace declaration, if the namespace URI is not empty:

>     DEFINE INPUT PARAMETER namespaceURI AS CHARACTER NO-UNDO.
>     DEFINE INPUT PARAMETER rootNodeName AS CHARACTER NO-UNDO.
>     DEFINE INPUT PARAMETER publicId AS CHARACTER NO-UNDO.
>     DEFINE INPUT PARAMETER systemId AS CHARACTER NO-UNDO.
>     DEFINE OUTPUT PARAMETER hDocument AS HANDLE NO-UNDO.
>     DEFINE VARIABLE hNsDecl AS HANDLE NO-UNDO.
>     DEFINE VARIABLE hRootNode AS HANDLE NO-UNDO.
>     DEFINE VARIABLE errStat AS LOGICAL NO-UNDO.
>     DEFINE VARIABLE found AS INTEGER NO-UNDO.

>     /* Create X-document and intialize it. */
>     CREATE X-DOCUMENT hDocument.
>     errStat = hDocument:INITIALIZE-DOCUMENT-TYPE(namespaceURI, rootNodeName,
>     publicId, systemId).
>     IF errStat = NO THEN
>     DO:
>       DELETE OBJECT hDocument.
>       LEAVE.
>     END.

>     /* If using namespaces, create X-NODEREF for namespace declaration. */
>     IF LENGTH(namespaceURI) > 0 THEN
>     DO:
>       CREATE X-NODEREF hNsDecl.
>       CREATE X-NODEREF hRootNode.

>       /* Look for a colonized name in rootNodeName. */
>       found = INDEX(rootNodeName, ":").
>       IF found > 0 THEN
>       DO:
>         /* Namespace declarations are special kinds of attributes that */
>         /* belong in the http://www.w3.org/2000/xmlns/ namespace.*/
>         errStat = hDocument:CREATE-NODE-NAMESPACE(hNsDecl,
>         "http://www.w3.org/2000/xmlns/", "xmlns:" +
>         SUBSTRING(rootNodeName, 1, found - 1), "attribute").
>       END.
>       ELSE
>       DO:
>         /* Use the default namespace, which does not need a */
>         /* namespace declaration prefix, and assign it to the */
>         /* http://www.w3.org/2000/xmlns/ namespace.*/
>         errStat = hDocument:CREATE-NODE-NAMESPACE(hNsDecl,
>         "http://www.w3.org/2000/xmlns/", "xmlns", "attribute").
>       END.
>       IF errStat = NO THEN
>         LEAVE.

>       /* Set the value of the namespace attribute to the namespace URI. */
>       hNsDecl:NODE-VALUE = namespaceURI.

>       /* Retrieve the root node and add the namespace declaration to it. */
>       errStat = hDocument:GET-DOCUMENT-ELEMENT(hRootNode).
>       IF errStat = NO THEN
>         LEAVE.
>       errStat = hRootNode:SET-ATTRIBUTE-NODE(hNsDecl).
>     END.

>     /* Free up the temporary X-NODEREFS. */
>     IF VALID-HANDLE(hNsDecl) THEN
>       DELETE OBJECT hNsDecl.
>     IF VALID-HANDLE(hRootNode) THEN
>       DELETE OBJECT hRootNode.

>     /* If an error occurred, free up the X-document. */
>     IF errStat = NO THEN
>       DELETE OBJECT hDocument.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095