PreviousNextIndex

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
root-node-name
public-id
system-id

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 NOT errStat 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, 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 NOT errStat 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 NOT errStat 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 NOT errStat THEN 
 DELETE OBJECT hDocument. 


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex