Kbase P10807: XML - DTD How to Set DTD in Versions 9.1C and later
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/05/2005 |
|
Status: Verified
GOAL:
How to set the XML DTD type
GOAL:
How to set the document type (i.e. DTD) for an XML document via the 4GL.
FACT(s) (Environment):
Progress 9.1C
FIX:
Prior to Progress 9.1C there was NO way to set this information due to a limitation in the parser Progress uses.
For Progress 9.1C and later use the INITIALIZE-DOCUMENT-TYPE() function to accomplish this. An example is shown below:
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<
errStat = hDocument:CREATE-NODE-NAMESPACE(hNsDecl,"http://www.w3.org/2000/xmlns/","xmlns:" + SUBSTRING(rootNodeName, 1, found - 1), "attribute").
ELSE
errStat = hDocument:CREATE-NODE-NAMESPACE(hNsDecl,"http://www.w3.org/2000/xmlns/","xmlns","attribute").
IF errStat = NO THEN
LEAVE.
hNsDecl:NODE-VALUE = namespaceURI.
errStat = hDocument:GET-DOCUMENT-ELEMENT(hRootNode).
IF errStat = NO THEN
LEAVE.
errStat = hRootNode:SET-ATTRIBUTE-NODE(hNsDecl).
END.
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.