Write-Xml - small problem

bigwill

Member
Hi guys

I am testing out write-xml method and have a problem with naming the nodes.


The simple test-program:

def temp-table tt
xml-node-name "entries"
field tf1 as char
field tf2 as int.


def var a as logical no-undo.


create tt.
assign tt.tf1 = 'test'
tt.tf2 = 123.
create tt .
assign tt.tf1 = 'test2'
tt.tf2 = 321.


/* Dump temp-table as xml */
a = temp-table tt:write-xml("file","c:\Temp\tt.xml",true,"ISO-8859-1",?,false,false).


Gives me this xml-file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<entries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<entriesRow>
<tf1>test</tf1>
<tf2>123</tf2>
</entriesRow>
<entriesRow>
<tf1>test2</tf1>
<tf2>321</tf2>
</entriesRow>
</entries>

My 2 problems are:
1. I don't wnat the "xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". Is it possible to specify not to write this into the file ?
2. My temp-table has name set to "entries". The write-xml method puts out every record with name: <entriesRow>. Is it possible to specify what this name should be.

This is the result i am looking for:
<?xml version="1.0" encoding="ISO-8859-1"?>
<entries>
<entry>
<tf1>test</tf1>
<tf2>123</tf2>
</entry>
<entry>
<tf1>test2</tf1>
<tf2>321</tf2>
</entry>
</entries>

Is it possible to get this result using write-xml or do i have to use sax-writeer ?


Thanks.

Lars E.
 

maretix

Member
Hi I am studying WRITE-XML Method me too....
I tested that name of TEMP-TABLE is to be the same name of XML'S ROOT ELEMENT and that TEMP-TABLE'S name fields are to be the same of XML'S CHILD ELEMENT...
 

GregTomkins

Active Member
I don't think that is possible, but, you could easily write a little XSLT to transform the Progress output to whatever tag names, etc. you need. So you would output the file using WRITE-XML and then call a Unix/Windows script to run an XSL script against the file. XSLT is kind of spooky but for a simple task like this shouldn't take long to figure out.
 

maretix

Member
I don't think that is possible, but, you could easily write a little XSLT to transform the Progress output to whatever tag names, etc. you need. So you would output the file using WRITE-XML and then call a Unix/Windows script to run an XSL script against the file. XSLT is kind of spooky but for a simple task like this shouldn't take long to figure out.

Hi Greg,
Many thanks for your kind reply.
I will study XSLT as i need to solve this problem...i need to modify some WEBSPEED procedures not written myself..
I 'd like to reduce lines of code ,,without using , where it si possibile , DOM ...
In fact i need to create an XML Document that me a thirdy part ask to me.
It contains ELEMENT and ATTRIBUTES together...

But i want to tell you that , i think today i read an interesting thing in ABL Reference about DEFINE TEMP-TABLE.
If i understood good...it is possible to define a TEMP-TABLE Field with a XML-NODE-TYPE Clause.
This Clause is a CHARACTHER Constant that would be ELEMENT , ATTRIBUTE,HIDDEN ...
I cannot attach the link of DEFINE TEMP-TABLE definition (i have no rights) but you can search XML-NODE-TYPE clause...


Perhaps there is a hope ,,,i am trying to find any examples...to find if it works...
If you are interested too to understand better,,write each other,,i think that it would be very useful also others people...

What i need to create...is an XML Documenti like that :::
(I was able to create that with WRITE-XML method BUT MY PROBLEM was /is to insert inside each element , attrubutes...)
Notice ELEMENT and inside ELEMENT one or more ATTRIBUTE...

<Tabella>
<P1 label="Prezzo unitario riservato al cliente (ECO-FEE compreso)">0,00000</P1>
<D1 label="Mag.%20Verona%20Vendita%20Std." a_value="120001">107</D1>
<D2 label="Mag.Legnago%20S.Pietro%20Vend.Std" a_value="120003">12</D2>
<CodiceAssociato label="Codice Interno">TIC0882@</CodiceAssociato>
</Tabella>

THANKS a LOT ...i hope to see another advices or messages ...
 

maretix

Member
Hi Greg,
Many thanks for your kind reply.
I will study XSLT as i need to solve this problem...i need to modify some WEBSPEED procedures not written myself..
I 'd like to reduce lines of code ,,without using , where it si possibile , DOM ...
In fact i need to create an XML Document that me a thirdy part ask to me.
It contains ELEMENT and ATTRIBUTES together...

But i want to tell you that , i think today i read an interesting thing in ABL Reference about DEFINE TEMP-TABLE.
If i understood good...it is possible to define a TEMP-TABLE Field with a XML-NODE-TYPE Clause.
This Clause is a CHARACTHER Constant that would be ELEMENT , ATTRIBUTE,HIDDEN ...
I cannot attach the link of DEFINE TEMP-TABLE definition (i have no rights) but you can search XML-NODE-TYPE clause...


Perhaps there is a hope ,,,i am trying to find any examples...to find if it works...
If you are interested too to understand better,,write each other,,i think that it would be very useful also others people...

What i need to create...is an XML Documenti like that :::
(I was able to create that with WRITE-XML method BUT MY PROBLEM was /is to insert inside each element , attrubutes...)
Notice ELEMENT and inside ELEMENT one or more ATTRIBUTE...

<Tabella>
<P1 label="Prezzo unitario riservato al cliente (ECO-FEE compreso)">0,00000</P1>
<D1 label="Mag.%20Verona%20Vendita%20Std." a_value="120001">107</D1>
<D2 label="Mag.Legnago%20S.Pietro%20Vend.Std" a_value="120003">12</D2>
<CodiceAssociato label="Codice Interno">TIC0882@</CodiceAssociato>
</Tabella>

======================================
Hi Greg, I confirm you it is possible to create ATTRBIUTES with WRITE-XML Method.
I did an example with a simple TEMP-TABLE.
You can also change the name of the node...in this case i changed name to ATTRIBUTES.
If you define attributes and element in the same temp.table, WRITE-XML put before all ATTRIBUTES in ALPHABETICAL order and then all ELEMENTS.
I'd like to discover also how to insert an ATTRIBUTE inside tags of a ELEMENT...
I do not know if i will be so lucky to discover that...
I foyu have qny god news ,,,post them !!!!

/*---------------------------------------*/
/***** Temp-Table Definiton *****/
/*--------------------------------------*/

DEF

TEMP-TABLE ttClienti

FIELD campolabel AS CHAR XML-NODE-TYPE "ATTRIBUTE" XML-NODE-NAME "Label"
FIELD codpdc AS CHAR

FIELD campolabel1 AS CHAR XML-NODE-TYPE "ATTRIBUTE" XML-NODE-NAME "A_Value"
FIELD ragsoc AS CHAR

FIELD cap AS CHAR

INDEX i1 codpdc.

/*-----------------------------------------------*/
/**** Invoking WRITE-XML Method *****/
/*-----------------------------------------------*/

ASSIGN
cTargetType =
"FILE"
cFile =
"C:\Xml\ttClienti.xml"
lFormatted =
YES
cEncoding = ?

cSchemaLocation = ?
lWriteSchema
=NO
lMinSchema = NO.
lReturn =
TEMP-TABLE ttClienti:WRITE-XML(cTargetType, cFile, lFormatted,
cEncoding, cSchemaLocation, lWriteSchema, lMinSchema).

/*----------------------------------*/
/* This in the output XML */
/*----------------------------------*/

<?xml version="1.0"?>
-<ttClienti xmlns:xsi="....">

-<ttClientiRow A_Value="Ragione Sociale" Label="Codice Cliente">
<codpdc>1301105500</codpdc>
<ragsoc>URAGANI SRL</ragsoc>
<cap>40033</cap>
</ttClientiRow>

</ttClienti>
 

Stefan

Well-Known Member
Hi guys

I am testing out write-xml method and have a problem with naming the nodes.

snip

Is it possible to get this result using write-xml or do i have to use sax-writeer ?

Wrap the temp-table in a dataset. The only thing still 'wrong' (although it is absolutely valid) is the xml namespace declaration.

Code:
DEFINE TEMP-TABLE tt1   SERIALIZE-NAME "entry"
   FIELD tf1   AS CHAR
   FIELD tf2   AS INT.

DEFINE DATASET ds SERIALIZE-NAME "entries" FOR tt1.


CREATE tt1. ASSIGN tt1.tf1 = "test" tt1.tf2 = 123.
CREATE tt1. ASSIGN tt1.tf1 = "test2" tt1.tf2 = 321.

DEF VAR lcc AS LONGCHAR.

DATASET ds:HANDLE:WRITE-XML( "longchar", lcc, TRUE, "iso8859-1" ).

MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.

Result

Code:
---------------------------
Message
---------------------------
<?xml version="1.0" encoding="iso8859-1"?>
<entries xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <entry>
    <tf1>test</tf1>
    <tf2>123</tf2>
  </entry>
  <entry>
    <tf1>test2</tf1>
    <tf2>321</tf2>
  </entry>
</entries>
---------------------------
OK  
---------------------------
 

Stefan

Well-Known Member
Hi Greg,
What i need to create...is an XML Documenti like that :::
(I was able to create that with WRITE-XML method BUT MY PROBLEM was /is to insert inside each element , attrubutes...)
Notice ELEMENT and inside ELEMENT one or more ATTRIBUTE...

<Tabella>
<P1 label="Prezzo unitario riservato al cliente (ECO-FEE compreso)">0,00000</P1>
<D1 label="Mag.%20Verona%20Vendita%20Std." a_value="120001">107</D1>
<D2 label="Mag.Legnago%20S.Pietro%20Vend.Std" a_value="120003">12</D2>
<CodiceAssociato label="Codice Interno">TIC0882@</CodiceAssociato>
</Tabella>

The following hack job will produce your XML...

Code:
DEFINE TEMP-TABLE ttP1   SERIALIZE-NAME "P1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute" 
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttD1   SERIALIZE-NAME "D1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute" 
   FIELD a_value  AS INT      XML-NODE-NAME "a_value" XML-NODE-TYPE "attribute" 
   FIELD value_   AS INT      XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttCA SERIALIZE-NAME "CodiceAssociato"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute" 
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .

DEFINE DATASET ds SERIALIZE-NAME "Tabella" FOR ttP1, ttD1, ttCA.


CREATE ttP1. ASSIGN ttP1.label_ = "Prezzo"   ttP1.value_ = "0,00000". /* xml decimals do not contain decimal commas */
CREATE ttD1. ASSIGN ttD1.label_ = "Mag"      ttD1.a_value = 120001 ttD1.value_ = 107.
CREATE ttCA. ASSIGN ttCA.label_ = "Intern"   ttCA.value_ = "TICO882@".

DEF VAR lcc AS LONGCHAR.

DATASET ds:HANDLE:WRITE-XML( "longchar", lcc, TRUE ).

MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.

Result

Code:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<Tabella xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <P1 label="Prezzo">0,00000</P1>
  <D1 label="Mag" a_value="120001">107</D1>
  <CodiceAssociato label="Intern">TICO882@</CodiceAssociato>
</Tabella>
---------------------------
OK  
---------------------------

But... you do not specify what multiple records look like :)
 

maretix

Member
The following hack job will produce your XML...

Code:
DEFINE TEMP-TABLE ttP1   SERIALIZE-NAME "P1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttD1   SERIALIZE-NAME "D1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD a_value  AS INT      XML-NODE-NAME "a_value" XML-NODE-TYPE "attribute"
   FIELD value_   AS INT      XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttCA SERIALIZE-NAME "CodiceAssociato"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .
 
DEFINE DATASET ds SERIALIZE-NAME "Tabella" FOR ttP1, ttD1, ttCA.
 
 
CREATE ttP1. ASSIGN ttP1.label_ = "Prezzo"   ttP1.value_ = "0,00000". /* xml decimals do not contain decimal commas */
CREATE ttD1. ASSIGN ttD1.label_ = "Mag"      ttD1.a_value = 120001 ttD1.value_ = 107.
CREATE ttCA. ASSIGN ttCA.label_ = "Intern"   ttCA.value_ = "TICO882@".
 
DEF VAR lcc AS LONGCHAR.
 
DATASET ds:HANDLE:WRITE-XML( "longchar", lcc, TRUE ).
 
MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.

Result

Code:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<Tabella xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <P1 label="Prezzo">0,00000</P1>
  <D1 label="Mag" a_value="120001">107</D1>
  <CodiceAssociato label="Intern">TICO882@</CodiceAssociato>
</Tabella>
---------------------------
OK 
---------------------------

But... you do not specify what multiple records look like :)


Ciao Stefan.
Thank you very much for your kind reply.
It is wonderful what you posted to me.
Thank you very much ...i was not so clever to use PRODATASET because i never use them.
I will save this example ...it is very useful now to understand it is possible to do that.

I have to modify WebSpeed Applications that generate XML Files with DOM.
I did not write them ..so i am studying 4GL and XML and what can i do ...
But i'd like to simplify these programs using WRITE-XML Method instead of DOM ...
Now you helped me to obtain an XML File in tha same manner that thirdy part company ask me to produce.
My problem was to understand how to write ATTRIBUTES together ELEMENT...
About multiple records , i have NO multiple records to generate,,,they ask me an XML with the same single structure i posted...

Thank you very much...again...

Regards.
 

maretix

Member
The following hack job will produce your XML...

Code:
DEFINE TEMP-TABLE ttP1   SERIALIZE-NAME "P1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttD1   SERIALIZE-NAME "D1"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD a_value  AS INT      XML-NODE-NAME "a_value" XML-NODE-TYPE "attribute"
   FIELD value_   AS INT      XML-NODE-TYPE "text"
   .
DEFINE TEMP-TABLE ttCA SERIALIZE-NAME "CodiceAssociato"
   FIELD label_   AS CHAR     XML-NODE-NAME "label"   XML-NODE-TYPE "attribute"
   FIELD value_   AS CHAR     XML-NODE-TYPE "text"
   .
 
DEFINE DATASET ds SERIALIZE-NAME "Tabella" FOR ttP1, ttD1, ttCA.
 
 
CREATE ttP1. ASSIGN ttP1.label_ = "Prezzo"   ttP1.value_ = "0,00000". /* xml decimals do not contain decimal commas */
CREATE ttD1. ASSIGN ttD1.label_ = "Mag"      ttD1.a_value = 120001 ttD1.value_ = 107.
CREATE ttCA. ASSIGN ttCA.label_ = "Intern"   ttCA.value_ = "TICO882@".
 
DEF VAR lcc AS LONGCHAR.
 
DATASET ds:HANDLE:WRITE-XML( "longchar", lcc, TRUE ).
 
MESSAGE STRING( lcc ) VIEW-AS ALERT-BOX.

Result

Code:
---------------------------
Message
---------------------------
<?xml version="1.0"?>
<Tabella xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <P1 label="Prezzo">0,00000</P1>
  <D1 label="Mag" a_value="120001">107</D1>
  <CodiceAssociato label="Intern">TICO882@</CodiceAssociato>
</Tabella>
---------------------------
OK 
---------------------------


Hi Stefan...sorry i disturb you again..do not hate me ...please..

Using yours useful examples i was able to use WRITE-XML Method instead of DOM ..to create an XML File in a CGI Wrapper program in WEBSPEED Environment..
If i use a target type LONGCHAR (as you posted) or FILE (as i did) i can obtain a variable or a file on a folder that really contains XML File as i want to generate...
My problem now is to POST XML FILE on WEBSTREAM ...in fact i am using a WEBSPEED program...
I read PROGRESS DOCUMENTATION ..it is possible to do that specifying target type as STREAM ...
I did a lot of examples ..but i was not able to do good results.
I open Browser , i type url of my Webspeed program, program run good but nothing output on browser.

I know in DOM ,it is necessary specify OUTPUT CONTENT XML i did (i write this declaration in outputheader section of my program..), then after creation of XML Document, writing before end of program..

XMLDocHandle:SAVE("stream", "webstream").

and XML File go through WEB and reaches companies who ask me that file XML...

How can i do that using WRITE-XML Method ????


DATASET ds:HANDLE:WRITE-XML( "stream", <what do i have to write here ???>, TRUE ).

Thanks Stefan.








But... you do not specify what multiple records look like :)
 

Stefan

Well-Known Member
The name of the stream - which in the case of WebSpeed is (as you used in your DOM example) "webstream".
 

maretix

Member
The name of the stream - which in the case of WebSpeed is (as you used in your DOM example) "webstream".

The name of the stream - which in the case of WebSpeed is (as you used in your DOM example) "webstream".

Hi Stefan.
Okay i understood the name of WEBSPEED stream is webstream...so i ha ve to write this in target-type ???

DATASET ds:HANDLE:WRITE-XML( "webstream", <what i need to write here >, TRUE ). /* is it correct ??? */

I tried also that below but it does not work ...
DATASET ds:HANDLE:WRITE-XML( "stream", "webstream",TRUE ).
Thanks..
 

Stefan

Well-Known Member
The "webstream" is simply a named stream used by WebSpeed to communicate with the web server. So I would expect write-xml( "stream", "webstream") to dump the contents to the web server.

If that 'does not work' - please define 'does not work' - examine the raw data you are receiving in your browser.
 

maretix

Member
The "webstream" is simply a named stream used by WebSpeed to communicate with the web server. So I would expect write-xml( "stream", "webstream") to dump the contents to the web server.

If that 'does not work' - please define 'does not work' - examine the raw data you are receiving in your browser.

Hi Stefan,

Return = hPDS:
WRITE-XML("stream","webstream",lFormatted, cEncoding, cSchemaLocation, lWriteSchema, lMinSchema).

It works !!!
So i solved my problem...i am very happy of that...
In this way i can modifiy 12 cgi wrappers programs using WRITE-XML Method instead DOM.
According my opinion , it is good practise, because i can have more easier and readable programs,,,
I found DOM more complicated ...
It does not mean , i'll never use DOM , perhaps i will use DOM only when XML File to create is too complicated for WRITE-XML Method.

Many thanks again...sorry for all time you spent regarding my post.

Thanks a lot.
 

Stefan

Well-Known Member
If you need to pick up more complex documents again - look at the SAX parser - it's simpler (at least that's what the S stands for).
 

maretix

Member
Hi Stefan.
Thanks for your advice...i do not know anything about SAX Parser ..i 'll try to study it..

Thanks again ..have a good day.
 
Top