Temp-table to XML example?

Posted by Admin on 13-Feb-2008 09:34

Hi,

I have this temp-table:

DEFINE TEMP-TABLE ttDestination
FIELD destName AS CHARACTER
FIELD duration AS CHARACTER
FIELD price AS CHARACTER
FIELD linkText AS CHARACTER
FIELD link AS CHARACTER.

How can I use the WRITE-XML() to get something like this:

'<?xml version="1.0" encoding="utf-8" ?>'
'<offers type="national" infoText="">'
'<destinations>'
'<destination name="Name goes here" duration="More info here" price="fr 2599:-" linkText="Click here" link="http://etcetc/" />'
''<destination name="Name goes here" duration="More info here" price="fr 2599:-" linkText="Click here" link="http://etcetc/" />'
'</destinations>'
'</offers>'


I know how to use X-DOCUMENT and things like this but it sounds easier if I could just :

1) Define the temp-table / DEFINE TEMP-TABLE...

2) Fill the temp-table / CREATE ttDestination....

3) Define the layout of the XML. / How?

4) Use WRITE-XML() to create the xml document.

All Replies

Posted by Robin Brown on 13-Feb-2008 10:40

Hi Jens,

You cannot define the layout of the XML document created by WRITE-XML. Your options here are to use the ABL DOM Api and X-DOCUMENT, as you mention, or use the 10.1A ABL SAX Api and the SAX-WRITER object, which should give you better performance over DOM.

Regards,

Robin Brown

Posted by Admin on 14-Feb-2008 02:38

Posted by jtownsen on 14-Feb-2008 04:53

Take a look in the documentation, particularly the ABL Reference for the temp-table object, buffer object and buffer-field object handles. There are a bunch of properties that will help you to structure an the result of the WRITE-XML method. Look for things like: NAMESPACE-* & XML-*. buffer-field-handle:XML-NODE-TYPE will be of particular interest.

That said, there are some restrictions on what you can do. If you need to do something more, like restructure table/field hierarchy levels, you can do that with XSLT.

Posted by Admin on 14-Feb-2008 04:57

If you need to go with XSLT, that means XML manipulation outside the ABL using 3rd Party tools (or Sonic ESB).

My favorite is to write ABL classes (10.1A +) that use my XML serialization framework which is also available on PSDN.

Posted by jtownsen on 14-Feb-2008 04:57

READ-XMLSCHEMA is only useful for read in from an xml document, not write out to one. It will allow you to dynamically create a temp-table or ProDataSet definition that matches the given schema. If you want to use READ-XMLSCHEMA instead of "DEFINE TEMP-TABLE", you should be able to use WRITE-XML to generate what you're looking for.

Posted by Admin on 15-Feb-2008 02:52

jtownsen wrote:

READ-XMLSCHEMA is only useful for read in from an xml document, not write out to one. It will allow you to dynamically create a temp-table or ProDataSet definition that matches the given schema. If you want to use READ-XMLSCHEMA instead of "DEFINE TEMP-TABLE", you should be able to use WRITE-XML to generate what you're looking for.

Aha, that basically means that I can only use dynamic style coding for the temp-tables right?

It sure would help of someone has a small example of code to show?

This thread is closed