Creating XML

John

New Member
Hi Team,

I am not getting XML output in desired format using below code. Could someone suggest in this?

Code:
 DEFINE VARIABLE cRequest AS LONGCHAR     NO-UNDO.
 
 Define temp-table tt-Code no-undo
    Code                  as char
    AccountRangeFrom      as char
    AccountRangeTo        as char
    SubAccountRangeFrom   as char
    SubAccountRangeTo     as char.
 
 TEMP-TABLE tt-Code:WRITE-XML("LONGCHAR",cRequest) NO-ERROR.
XML signature in WSDL:

XML:
 <ns0:CCCode xmlns:ns0="http:/url.com/file.xsd">
  <ns0:Code>string-value</ns0:Code>
  <ns0:AccountRangeFrom>string-value</ns0:AccountRangeFrom>
  <ns0:AccountRangeTo>string-value</ns0:AccountRangeTo>
  <ns0:SubAccountRangeFrom>string-value</ns0:SubAccountRangeFrom>
  <ns0:SubAccountRangeTo>string-value</ns0:SubAccountRangeTo>
</ns0:CCCode>
Desired XML Output. One code has multiple ranges for account and sub account hence need to be export data in below format:

XML:
 <ns0:CCCode xmlns:ns0="http:/url.com/file.xsd">
  <ns0:Code>string-value</ns0:Code>
  <ns0:AccountRangeFrom>Frm-1</ns0:AccountRangeFrom>
  <ns0:AccountRangeTo>To-1</ns0:AccountRangeTo>
  <ns0:AccountRangeFrom>Frm-2</ns0:AccountRangeFrom>
  <ns0:AccountRangeTo>To-2</ns0:AccountRangeTo>
  <ns0:AccountRangeFrom>Frm-3</ns0:AccountRangeFrom>
  <ns0:AccountRangeTo>To-3</ns0:AccountRangeTo>
  <ns0:SubAccountRangeFrom>Frm-Sub-1</ns0:SubAccountRangeFrom>
  <ns0:SubAccountRangeTo>To-Sub-1</ns0:SubAccountRangeTo>
  <ns0:SubAccountRangeFrom>Frm-Sub-2</ns0:SubAccountRangeFrom>
  <ns0:SubAccountRangeTo>To-Sub-2</ns0:SubAccountRangeTo>
</ns0:CCCode>
Thanks
 

Cecil

19+ years progress programming and still learning.
Hi John,

Do you have access to the XSD file?
I've created this one, but it would be interesting how it compairs to the orignal.
Code:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http:/url.com/file.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Code" type="xs:string"/>
  <xs:element name="AccountRangeFrom" type="xs:string"/>
  <xs:element name="AccountRangeTo" type="xs:string"/>
  <xs:element name="SubAccountRangeFrom" type="xs:string"/>
  <xs:element name="SubAccountRangeTo" type="xs:string"/>
  <xs:element name="CCCode">
    <xs:complexType>
      <xs:choice maxOccurs="unbounded" minOccurs="0">
        <xs:element ref="file:Code" xmlns:file="http:/url.com/file.xsd"/>
        <xs:element ref="file:AccountRangeFrom" xmlns:file="http:/url.com/file.xsd"/>
        <xs:element ref="file:AccountRangeTo" xmlns:file="http:/url.com/file.xsd"/>
        <xs:element ref="file:SubAccountRangeFrom" xmlns:file="http:/url.com/file.xsd"/>
        <xs:element ref="file:SubAccountRangeTo" xmlns:file="http:/url.com/file.xsd"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>
Without using the SAX-WRITER, or X-DOCUMENT, I don't think it's possible to use the WRITE-XML() method.

This is a better XML design, but it guess it wont help wou.
Code:
<ns0:CCCode xmlns:ns0="http:/url.com/file.xsd">
  <ns0:Code>string-value</ns0:Code>
    <ns0:AccountRanges>
        <ns0:AccountRange>
            <ns0:AccountRangeFrom>Frm-1</ns0:AccountRangeFrom>
            <ns0:AccountRangeTo>To-1</ns0:AccountRangeTo>
        </ns0:AccountRange>
        <ns0:AccountRange>
            <ns0:AccountRangeFrom>Frm-2</ns0:AccountRangeFrom>
            <ns0:AccountRangeTo>To-2</ns0:AccountRangeTo>
        </ns0:AccountRange>
        <ns0:AccountRange>
            <ns0:AccountRangeFrom>Frm-3</ns0:AccountRangeFrom>
            <ns0:AccountRangeTo>To-3</ns0:AccountRangeTo>
        </ns0:AccountRange>
    </ns0:AccountRanges> 
    <ns0:SubAccountRanges>
        <ns0:SubAccountRange>
            <ns0:SubAccountRangeFrom>Frm-Sub-1</ns0:SubAccountRangeFrom>
            <ns0:SubAccountRangeTo>To-Sub-1</ns0:SubAccountRangeTo>
        </ns0:SubAccountRange>
        <ns0:SubAccountRange>
            <ns0:SubAccountRangeFrom>Frm-Sub-2</ns0:SubAccountRangeFrom>
            <ns0:SubAccountRangeTo>To-Sub-2</ns0:SubAccountRangeTo>
        </ns0:SubAccountRange>
    </ns0:SubAccountRanges>     
</ns0:CCCode>

This is a refinement of your existing code.
Code:
DEFINE TEMP-TABLE CCCode NO-UNDO
    NAMESPACE-URI "http:/url.com/file.xsd"
    FIELD Code AS CHARACTER
    FIELD AccountRangeFrom AS CHARACTER
    FIELD AccountRangeTo AS CHARACTER
    FIELD SubAccountRangeFrom AS CHARACTER
    FIELD SubAccountRangeTo AS CHARACTER .

DEFINE DATASET CCCodeDset NAMESPACE-URI "http:/url.com/file.xsd"
    XML-NODE-TYPE "HIDDEN"
    FOR CCCode.

DEFINE VARIABLE lcXMLContent AS LONGCHAR NO-UNDO. 
  
  
CREATE CCCode.

ASSIGN
    CCCode.AccountRangeFrom  = "FooBar1"
    CCCode.AccountRangeTo    = "FooBar2"
    CCCode.SubAccountRangeFrom = "FooBar3"
    CCCode.SubAccountRangeTo   = "FooBar4".
  
DATASET CCCodeDset:WRITE-XML("LONGCHAR", lcXMLContent, TRUE).

MESSAGE STRING(lcXMLContent)
    VIEW-AS ALERT-BOX INFO.
 
Last edited:
Top