Try OpenEdge Now
skip to main content
Working with XML
Reading and Writing XML Data from Temp-Tables and ProDataSets : Sample ProDataSet to XML round-trip : Mapping ABL names to different XML element or attribute names
 

Mapping ABL names to different XML element or attribute names

If you have XML Documents or XML Schemas that you import and export through ABL, you can always adjust your ABL definitions or XML Schema to use identical names. In some cases, you may be working with pre-existing ABL definitions and XML Schema that cannot be easily changed. The XML-NODE-NAME or SERIALIZE-NAME attributes on a ProDataSet object handle, temp-table object, temp-table buffer object, or buffer field object allows you to specify an XML element (or attribute) name for the ABL object. For more information on the interaction of these attributes, see XML-NODE-NAME and SERIALIZE-NAME.
You can set these attributes on the DEFINE BUFFER, DEFINE DATASET, or DEFINE TEMP-TABLE statement by using the corresponding options. You can set them for a buffer field using the field definition options of the DEFINE TEMP-TABLE statement. You can also directly set the XML-NODE-NAME or SERIALIZE-NAME attributes on the object handle.
These attributes allow you to work around ABL names that use illegal XML characters or to work around XML element or attribute names that are reserved words in ABL.
The ABL READ-XMLSCHEMA( ) method and the xsdto4gl utility create ABL temp-table or ProDataSet definitions with the correct ABL names.
The following example demonstrates the use of the attribute by mapping names illegal in ABL or XML to an acceptable substitute:
/* pi-tfx-write-12.p */

DEFINE VARIABLE hdset   AS HANDLE  NO-UNDO.
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE ttCustomer% NO-UNDO XML-NODE-NAME "ttCustSafe"
   FIELD Cust#   AS INTEGER XML-NODE-NAME "custNo"
   FIELD Name    AS CHARACTER XML-NODE-TYPE "ATTRIBUTE" XML-NODE-NAME "Name1"
   FIELD Country AS CHARACTER
   INDEX CustNum IS UNIQUE PRIMARY Cust#.

DEFINE TEMP-TABLE ttOrd$ NO-UNDO XML-NODE-NAME "ttOrdSafe"
   FIELD Order# AS INTEGER XML-NODE-NAME "OrderNum"
   FIELD Cust# AS INTEGER XML-NODE-NAME "custNo"
   INDEX OrderNum IS UNIQUE PRIMARY Order#.

DEFINE DATASET dsCustOrd& NAMESPACE-URI "urn:myds"
   XML-NODE-NAME "dsCO" FOR ttCustomer%, ttOrd$
   DATA-RELATION custOrd FOR ttCustomer%, ttOrd$
     RELATION-FIELDS (Cust#, Cust#) NESTED.

hdset = DATASET dsCustOrd&:HANDLE.

CREATE ttCustomer%.
ASSIGN ttCustomer%.Cust# = 10
ttCustomer%.Name  = "Round Trip Inc".

CREATE ttOrd$.
ASSIGN ttOrd$.Cust#  = 10
ttOrd$.Order# = 95.

lReturn = hdset:WRITE-XML("file", "dsCustOrd12.xml", YES).
lReturn = hdset:WRITE-XMLSCHEMA("file", "dsCustOrd12.xsd", YES).
This is the XML Document written by the code:
<?xml version="1.0"?>
<dsCO xmlns="urn:myds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ttCustSafe xmlns="urn:myds" Name1="Round Trip Inc">
<custNo>10</custNo>
<Country/>
<ttOrdSafe>
<OrderNum>95</OrderNum>
<custNo>10</custNo>
</ttOrdSafe>
</ttCustSafe>
</dsCO>