× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Your example does seem to work well Birgitta - but even the simplest of XML documents usually requires a bit more "shape". The script as given (modified a bit to fit a DB I had to hand) produces this:

<Customers>
<Customer>
<ID>A0011</ID>
<PersName>Acme Best Brew </PersName>
<ZipCode>0</ZipCode>
<Zip-Plus>0</Zip-Plus>
<City>Acme </City>
</Customer>
... repeat Customer element

But what I wanted was:

<Customers>
<Customer>
<ID>A0011</ID>
<PersName>Acme Best Brew </PersName>
<Address> <<<< New compound element
<ZipCode>55901</ZipCode>
<Zip-Plus></Zip-Plus>
<City>Acme </City>
</Address>
</Customer>

And I have looked throughout the IBM and other examples and have not been able to see how this is done. In all the other approaches described in this thread providing this "shape" is trivial. I'd love to know how the SQL approach handles it.

Also Zip-Plus is commonly an optional element and should not be present when empty - how do I achieve that?


On 2014-08-20, at 12:57 AM, Birgitta Hauser <Hauser@xxxxxxxxxxxxxxx> wrote:

Hi Brian,

You may check the following article:
Using RPG to exploit IBM DB2 XML support
http://www.ibm.com/developerworks/ibmi/library/i-using-rpg/index.html

Using embedded SQL or better Reference Files is an even easier way for
writing the result to the IFS. (The most complex part is building the SQL
statement for generating the XML document.

The following souce code is a complete program for generating an XML
document and writing this document directly to the IFS:

D MyXMLDoc S SQLTYPE(XML_CLOB_File)
D
//***********************************************************************
/Free
Exec SQL Set Option Commit=*None, DatFmt=*ISO, CloSQLCsr=*EndActGrp;

Clear MyXMLDoc;
MyXMLDoc_Name = '/home/Hauser/WrtSQLXML.xml';
MyXMLDoc_NL = %Len(%Trim(MyXMLDoc_Name));
MyXMLDoc_FO = SQFOVR; //Replace if exists

Exec SQL
Select XmlDocument
(xmlgroup(EmployeeNo as "PersNo",
Trim(Trim (FirstName) concat ' ' concat
Trim(Name)) as "PersName",
Address as "Street",
ZipCode as "ZipCode",
City as "City"
Order By City Desc, Name
Option Row "Employee"
Root "Staff"))
into :MyXMLDoc
From LobStaff;

If SQLCODE < *Zeros;
Dsply 'Error occured';
else;
Dsply 'XML Document generated';
EndIf;

*InLR = *On;
/End-Free

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"

-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Brian
Stapleton
Gesendet: Tuesday, 19.8 2014 21:56
An: rpg400-l@xxxxxxxxxxxx
Betreff: Writing XML with RPGLE V7R1M0

Good Afternoon

I need to learn how to write XML documents with RPGLE V7R1M0 onto our IFS.

How can I educate myself on doing this?

I would prefer to stay as native RPGLE as possible, and am not looking to
purchase a 3rd party solution.





Brian Stapleton
Information Services
Carhartt, Inc
5750 Mercury Drive
Dearborn, MI 48126
Desk - 313-749-6586
Fax - 313-271-3455
BStapleton@xxxxxxxxxxxx<mailto:BStapleton@xxxxxxxxxxxx>

[Description: Description: Carhartt_emaillogo]


Confidential: This electronic message and all contents contain information
from Carhartt, Inc. and its affiliates which may be confidential or
otherwise protected from disclosure. The information is intended to be for
the addressee only. If you are not the addressee, any disclosure, copy,
distribution or use of the contents of this message is prohibited. If you
have received this electronic message in error, please notify us immediately
at (313) 271-8460 and destroy the original message and all copies.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.


--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.