× 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.



Hi Jim,

that is not as difficult.
You split your SQL-Statement into multiple Common Table Expressions that
construct the XML components. These CTEs are joined together and for
building the next component until the XML document is completed in the Final
Select.

Look at the following XML document:
<Request>
<Product>
ProductA
<Profile>
ProfileA
<Data>
<Field1>Field1A</Field1>
<Field2>2018-03-10</Field2>
</Data>
<NewGroup>
<Field3>10,56</Field3>
<Field4>Field4A</Field4>
</NewGroup>
</Profile>
</Product>
<Product>
ProductB
<Profile>
ProfileB
<Data>
<Field1>Field1B</Field1>
<Field2>2018-03-09</Field2>
</Data>
<NewGroup>
<Field3>125,20</Field3>
<Field4>Field4B</Field4>
</NewGroup>
</Profile>
</Product>
</Request>

This XML Document is generated by the following SQL-Statement
With x as (Select *
From (Values('ProductA', 'ProfileA', 'Field1A', Current_Date,
10,56 , 'Field4A'),
('ProductB', 'ProfileB', 'Field1B', Current_Date -
1 Day, 125,2 , 'Field4B'))
x (Product, Profile, Field1, Field2, Field3, Field4)),

-- Build the Data and NewGroup components
y as (Select Product, Profile, xmlrow(Field1 as "Field1",
Field2 as "Field2"
Option row "Data") yData,
xmlrow(Field3 as "Field3",
Field4 as "Field4"
Option row "NewGroup") yNewGroup

from x),

-- Build the nexted elements Product, Profile, with Data and NewGroup

z as (Select Product, Profile, XMLElement(Name "Product", Product,
XMLElement(Name "Profile", Profile,
yData,
yNewGroup)) zProduct
from y)

-- Final Select aggregate the different rows and include this information in
an root element
Select XMLElement(Name "Request", XMLAgg(zProduct))
from z;

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!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)


-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxx> On Behalf Of Jim L. Bostwick
Sent: Freitag, 9. März 2018 22:43
To: rpg400-l@xxxxxxxxxxxx
Subject: Creating XML document via SQL - Db2 for i 7.2

I am trying to create an XML document using SQL and am having a very
difficult time just using the SQL XML Programming Manual and the SQL
Reference.

I am trying to create a document that looks like this, writing out to an IFS
file.

<Request>
<Product>
<Profile>
<Data>
<field1>1</field1>
<field2>2</field2>
</Data>
<NewGroup>
<field3>1</field3>
<field4>2</field4>
</NewGroup>
</Profile>
</Product>
</Request>

I am really looking for more than a 1 liner on what the various functions do
like XMLCONCAT (and a couple examples), or how do you create parent/child
groupings like product/profile....
Trial and error is driving me crazy (er)......

TIA

Jim Bostwick

--
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: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related questions.

Help support midrange.com by shopping at amazon.com with our affiliate link:
http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.