XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
v iSubject: XPath query
Author: v i
Date: 31 Aug 2007 12:59 PM
Hi,
I'm a newbie.

Have an XML file stored as CLOB in a db table.
Here's the reduced version of the file:

<?xml version="1.0" encoding="UTF-8" ?>

<TRANSFORM>

<KEY OLD="drinker" new="3" TRANSFORM1="specified">

<VALUE OLD="-1" new="-1" DESCRIPTION="NA" />

<VALUE OLD="0" new="0" DESCRIPTION="no" />

<VALUE OLD="1" new="1" DESCRIPTION="yes" />

</KEY>

<KEY OLD="runner" new="4" TRANSFORM1="specified">

<VALUE OLD="-1" new="-1" DESCRIPTION="NA" />

<VALUE OLD="0" new="0" DESCRIPTION="no" />

<VALUE OLD="1" new="1" DESCRIPTION="yes" />

</KEY>
</TRANSFORM>

I need to extract the attribute values and insert those into another db table with columns like: key_old, key_new, transform1, value_old, value_new, description.

I'm struggling with writing a SELECT query that will get me the correct result set. Can someone please, guide me through this?

So far I came up with:

SELECT XMLType(xmldoc).extract('/transform//key/value/@description') -- all 'description' attribute values of <value> element
from xml_documents tbl

but this brings one long string of all values...

Postnext
Minollo I.Subject: XPath query
Author: Minollo I.
Date: 31 Aug 2007 02:52 PM
Have you tried using DataDirect XQuery (http://www.xquery.com) to do that?

DataDirect XQuery is bundled in Stylus Studio, and you can experiment with it. The solution to your problem would look something similar to this, assuming "demo" is the table containing the result:

for $row in collection("pubs.dbo.xml_documents")/xml_documents
return
let $xmldoc := (# ddtek:evaluate-in-memory #) {$row/xmldoc}
return
for $key in $xmldoc/TRANSFORM/KEY
for $value in $key/VALUE
return
ddtek:sql-insert("demo", "key_old", string($key/@OLD), "key_new", string($key/@new), "transform1", string($key/@TRANSFORM1), "value_old", string($value/@OLD), "value_new", string($value/@new), "description", string($value/@DESCRIPTION))

Posttop
v iSubject: XPath query
Author: v i
Date: 31 Aug 2007 04:48 PM
thank u.

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.