Subject:convert text to xml from more than one source? Author:Phillip Ankerson Date:21 Aug 2008 12:12 PM
I have watched the video tutorial on how to create a customer xml converter for a text file, and have done that with a relatively simple text file. I need to read from more than one source (perhaps two text files - one for customers and one for addresses) or a database file, and create and xml file according to a spec I was given. Is this something that must be done with XQuery, or can it be done at all? We are creating an interface with Websphere...is there a pre-defined connector for this?
Subject:convert text to xml from more than one source? Author:Minollo I. Date:21 Aug 2008 12:47 PM
You can do that with XQuery, yes; joining data across multiple XML and/or non-XML files and/or database tables. In your case, something similar to this (using the built-in CSV converter; if the format is CSV, you don't need to create a custom one):
<root> {
for $row1 in doc("converter:CSV?c:/file1.csv")//row,
$row2 in doc("converter:CSV?c:/file2.csv")//row
where $row1/column.2 = $row2/column.3
return
<data>
<somedata>{$row1/column.0/text()}</somedata>
<moredata>{$row2/column.0/text()}</moredata>
</data>
} </root>
If the first row of the CSV contains "field names", then it's even easier, and you can get better element names in the output using "converter:CSV:first=yes?...". If you want to share some real example, we can create a sample XQuery for you.
You can integrate DataDirect XQuery/XML Converters in any Java application; so, you can surely integrate that in your WebSphere application. We do have an XQuery based servlet implementation (with sources available) that can expose virtually any XQuery as a Web service without any additional code; and it's compatible with WebSphere (see http://www.xquery.com/examples/web-service-example/xquerywebservice/).