If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Preserve XML in VARCHAR column

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-10, 10:08
sigmazen sigmazen is offline
Registered User
 
Join Date: Jan 2010
Posts: 6
Preserve XML in VARCHAR column

Hi
I am using zOS DB2 9 and have a table which contains a varchar field which contains xml data.
I want to pull this column, and another couple of integer columns to create a complete xml document.
However, when I extract the xml from the varchar, the xml querying thinks it is text and convert the less than / greater than to the "<" html values which isn't what I want.
I almost need an XMLPRESERVE type function.
Here is an example of a query to demonstrate (it's in quotes in case any conversion happens)

"SELECT XML2CLOB(XMLCONCAT(
XMLELEMENT(NAME "Value", 1)
,XMLELEMENT(NAME "Test", '<TagOne>1</TagOne>')
)) FROM SYSIBM.SYSDUMMY1"
Note: The <TagOne>1</TagOne> value would come from my varchar column in the real query.

This outputs:
<Value>1</Value><Test>&lt;TagOne&gt;1&lt;/TagOne&gt;</Test>

The output I actually want is:
<Value>1</Value><Test><TagOne>1</TagOne></Test>

Anyone with any ideas?
Thanks in advance
Simon
Reply With Quote
  #2 (permalink)  
Old 01-22-10, 10:19
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
A string is not an XML document. It is a value inside an XML doc. You need do parse the string to create an XML document. Then you can combine this document with other XML elements. Have a look at the XMLPARSE() function.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #3 (permalink)  
Old 01-22-10, 10:58
sigmazen sigmazen is offline
Registered User
 
Join Date: Jan 2010
Posts: 6
wow ... thanks knut
that works a treat :-)

SELECT XML2CLOB(XMLELEMENT(NAME "Test", XMLPARSE('<TagOne>1</TagOne>'))
) FROM SYSIBM.SYSDUMMY1

You star
Reply With Quote
Reply

Tags
db2, xml, zos

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On