<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codedrop™ Weblog &#187; XMLDB</title>
	<atom:link href="http://www.codedrop.ca/blog/archives/tag/xmldb/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codedrop.ca/blog</link>
	<description>Drop'n some code and other tech tidbits...</description>
	<lastBuildDate>Mon, 26 Jul 2010 16:45:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Returning raw XML string from Oracle XDB within Groovy / Grails</title>
		<link>http://www.codedrop.ca/blog/archives/101</link>
		<comments>http://www.codedrop.ca/blog/archives/101#comments</comments>
		<pubDate>Mon, 13 Jul 2009 16:11:16 +0000</pubDate>
		<dc:creator>groll</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Grails]]></category>
		<category><![CDATA[Groovy]]></category>
		<category><![CDATA[XMLDB]]></category>

		<guid isPermaLink="false">http://www.codedrop.ca/blog/archives/101</guid>
		<description><![CDATA[Here&#8217;s a quick solution for trying to extract the raw xml string from an Oracle XDB database when working with Grails.
After an initial attempt to hardcode a hibernate query to return the raw sql using .getStringVal() as follows:
  SELECT x.id, x.xmlData xmldata.getStringVal(), lines.*
  FROM xml_requests x
       XMLTable('declare [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick solution for trying to extract the raw xml string from an <a href="http://www.oracle.com/technology/tech/xml/xmldb/index.html">Oracle XDB</a> database when working with Grails.</p>
<p>After an initial attempt to hardcode a hibernate query to return the raw sql using .getStringVal() as follows:</p>
<pre>  SELECT x.id, x.xmlData xmldata.getStringVal(), lines.*
  FROM xml_requests x
       XMLTable('declare default element namespace
				"http://www.foo.com/fooservice";
                for $i in /XXXResponse/ResponseData/*/node()
                where $i/*:Error/*:Code = "0"
                return $i'
                PASSING x.xmldata
                COLUMNS GivenName NVARCHAR2(200)
	          PATH './*:PersonAdresseData/*:Person/*:Navn/*:Fornavne',
                    Surname  NVARCHAR2(200)
	          PATH './*:PersonAdresseData/*:Person/*:Navn/*:Efternavn') lines
  WHERE ....</pre>
<p>I found that the query would blow up if the xml string returned exceeded some threshold.  Approx ~ 2000 chars as I&#8217;m using an oracle database.</p>
<p>Solution was relatively simple thanks to the various support libraries Oracle brings to the table.</p>
<p>Add the <strong>xdb.jar</strong> and <strong>xmlparserv2.jar</strong> libraries from the Oracle installation into your Grails application /lib directory and then modify the .gsp page to handle the custom type accordingly as below:</p>
<pre>  &lt;div class="list"&gt;
    &lt;table&gt;
      &lt;thead&gt;
      &lt;tr&gt;
        &lt;g:each var="key" in="${list[0].keySet()}"&gt;
          &lt;g:sortableColumn property="${key}" title="${key}"/&gt;
        &lt;/g:each&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;g:each in="${list}" status="i" var="item"&gt;
        &lt;tr class="${(i % 2) == 0 ? 'odd' : 'even'}"&gt;
          &lt;g:each var="key" in="${list[0].keySet()}"&gt;
            &lt;td&gt;
            &lt;g:if test="${item[key] instanceof oracle.xdb.XMLType}"&gt;
              ${item[key].getStringVal()}
            &lt;/g:if&gt;
            &lt;g:else&gt;
              ${item[key]}
            &lt;/g:else&gt;
            &lt;/td&gt;
          &lt;/g:each&gt;
        &lt;/tr&gt;
      &lt;/g:each&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;</pre>
<p>** The above code will dynamically render a table view using the column names as headers in an HTML table. In my eaxmple one the columns I wanted to display was XMLType and stored in Oracle XDB format.</p>
<p><span style="font-family: sans-serif;"> </span></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Returning+raw+XML+string+from+Oracle+XDB+within+Groovy+%2F+Grails+http://3m4gf.th8.us" title="Post to Twitter"><img class="nothumb" src="http://www.codedrop.ca/blog/wp-content/plugins/tweet-this/icons/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Returning+raw+XML+string+from+Oracle+XDB+within+Groovy+%2F+Grails+http://3m4gf.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.codedrop.ca/blog/archives/101/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
