dbTalk Databases Forums  

XML output

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss XML output in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
brunoalsantos
 
Posts: n/a

Default XML output - 05-28-2010 , 08:57 AM






Hi all,

DB2 LUW V9.5 Fp5.

I would like to transform a result set in a XML output.
Using my statement, I've got this result set ...

<DATA>
<MACHINE_ID>
000103E1DE54FA3CD3B21542
<DEPARTMENT_NAME>100000001-MAQUINA NAO CADASTRADA - REGIONAL:
HX30</DEPARTMENT_NAME>
<MACHINE_HOSTNAME>AF106692</MACHINE_HOSTNAME>
<MACHINE_ID>
</DATA>
<DATA>
<MACHINE_ID>
000103E1DDEC0923F4751549
<DEPARTMENT_NAME>110014205-INFO PREPARACAO DE DOCUMENTOS</
DEPARTMENT_NAME>
<MACHINE_HOSTNAME>PREDOC123692</MACHINE_HOSTNAME>
<MACHINE_ID>
</DATA>

....


I need an output that looks the following:

<DATA>
<MACHINE_ID>
000103E1DE54FA3CD3B21542
<DEPARTMENT_NAME>100000001-MAQUINA NAO CADASTRADA - REGIONAL: HX30</
DEPARTMENT_NAME>
<MACHINE_HOSTNAME>AF106692</MACHINE_HOSTNAME>
</MACHINE_ID>
<MACHINE_ID>
000103E1DDEC0923F4751549
<DEPARTMENT_NAME>110014205-INFO PREPARACAO DE DOCUMENTOS</
DEPARTMENT_NAME>
<MACHINE_HOSTNAME>PREDOC123692</MACHINE_HOSTNAME>

<MACHINE_ID>
</DATA>


In other words: I need to put a <data> tag before the first line of
the result set, and include a </data> after the last line.

My statement is:

select
XMLELEMENT(NAME DATA,
XMLELEMENT(NAME MACHINE_ID, T.MACHINE_ID,
XMLELEMENT(NAME DEPARTMENT_NAME, D.DEPARTMENT_NAME) ,
XMLELEMENT(NAME MACHINE_HOSTNAME, T.MACHINE_HOSTNAME)))

FROM T;


Thanks in advance.

Reply With Quote
  #2  
Old   
Tonkuma
 
Posts: n/a

Default Re: XML output - 05-28-2010 , 09:56 AM






Please try:
XMLGROUP( ..... ROOT "DATA")

Reply With Quote
  #3  
Old   
brunoalsantos
 
Posts: n/a

Default Re: XML output - 05-28-2010 , 01:15 PM



On 28 maio, 11:56, Tonkuma <tonk... (AT) fiberbit (DOT) net> wrote:
Quote:
Please try:
XMLGROUP( ..... ROOT "DATA")
Thanks Tonkuma, works fine here.

But I've got another question ..

My output has a large string , and I received the folowing message
from CLP.

DB29320W Output has been truncated.

How Can I resolves this warning? I used XMLSERIALIZE ( .. ) but the
result was the same ...

Regards,
Bruno.

Reply With Quote
  #4  
Old   
Tonkuma
 
Posts: n/a

Default Re: XML output - 05-28-2010 , 03:02 PM



What data type in the XMLSERIALIZE did you specified?

Was that still too long?
For example: CLOB.
(Default for CLOB is CLOB(1M). )

How about something like VARCHAR(1000)?

Reply With Quote
  #5  
Old   
brunoalsantos
 
Posts: n/a

Default Re: XML output - 05-28-2010 , 03:32 PM



On 28 maio, 17:02, Tonkuma <tonk... (AT) fiberbit (DOT) net> wrote:
Quote:
What data type in the XMLSERIALIZE did you specified?

Was that still too long?
For example: CLOB.
(Default for CLOB is CLOB(1M). )

How about something like VARCHAR(1000)?
I specified CLOB ..

My statement ..

select
XMLSERIALIZE(
XMLGROUP(
T.MACHINE_ID,
D.DEPARTMENT_NAME,
T.MACHINE_HOSTNAME
OPTION ROOT "desktop") AS CLOB (50M))

FROM
ASSET.TBL_ASSET_MACHINE_ID T
INNER JOIN ASSET.TBL_ASSET_DEPARTMENT D ON (T.DEPARTMENT_ID =
D.DEPARTMENT_ID)

;

Result on CLP ..

......
NAME>BSARO1-006</MACHINE_HOSTNAME></
row><row><MACHINE_ID>0001023C44E759AF89131534</
MACHINE_ID><DEPARTMENT_NAME>RIO</
DEPARTMENT_NAME><MACHINE_HOSTNAME>RBOMR1-005</MACHINE_HOSTNAME></row>
DB29320W Output has been truncated.

Thanks.

Reply With Quote
  #6  
Old   
Frederik Engelen
 
Posts: n/a

Default Re: XML output - 05-29-2010 , 06:20 AM



On 28 mei, 22:32, brunoalsantos <brunoalsan... (AT) gmail (DOT) com> wrote:
Quote:
On 28 maio, 17:02, Tonkuma <tonk... (AT) fiberbit (DOT) net> wrote:

What data type in the XMLSERIALIZE did you specified?

Was that still too long?
For example: CLOB.
(Default for CLOB is CLOB(1M). )

How about something like VARCHAR(1000)?

I specified CLOB ..

My statement ..

select
XMLSERIALIZE(
* *XMLGROUP(
* * * T.MACHINE_ID,
* * * D.DEPARTMENT_NAME,
* * * T.MACHINE_HOSTNAME
* *OPTION ROOT "desktop") AS CLOB (50M))

FROM
ASSET.TBL_ASSET_MACHINE_ID T
INNER JOIN ASSET.TBL_ASSET_DEPARTMENT D ON (T.DEPARTMENT_ID =
D.DEPARTMENT_ID)

;

Result on CLP ..

.....
NAME>BSARO1-006</MACHINE_HOSTNAME></
row><row><MACHINE_ID>0001023C44E759AF89131534</
MACHINE_ID><DEPARTMENT_NAME>RIO</
DEPARTMENT_NAME><MACHINE_HOSTNAME>RBOMR1-005</MACHINE_HOSTNAME></row
DB29320W *Output has been truncated.

Thanks.
Hello Bruno,

The message you're seeing is coming from the DB2 CLP (client), not
from the server itself. Could you use another client to retrieve the
same string? In the past, I used Java to export such large XML
documents from DB2.

Off topic: if you want some fun, try Groovy, you'll love it.

--
Frederik Engelen

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.