Project

Profile

Help

Import data from flat files with XQuery

Added by Anonymous about 15 years ago

Legacy ID: #6599700 Legacy Poster: NickDiamond (nickdiamond_80)

Hello, is it possible to import a flat file (or more than one at once) with XQuery ? For example I want to import a small txt-file and use the content to build a new XML file. At the moment I first create a XML file like that : ... <root> <content>here I just paste the content of the txt</content> </root> Is there a direkt way to import the content of the txt.file ? I have to admit that I use java to start the xquery. maybe there is a way to "push" the content into the XQuery like a stream or something that way. ( maybe with "DynamicQueryContext" or "staticqueryContext" !!???!! ) Sorry, if my english is not that correct ;) greets and thank you, ND


Replies (4)

Please register to reply

RE: Import data from flat files with XQuery - Added by Anonymous about 15 years ago

Legacy ID: #6600047 Legacy Poster: Michael Kay (mhkay)

XSLT has a function unparsed-text() to read a text file at a given URI, but unfortunately there's no equivalent in XQuery. If you can read the contents of the file into a string before the query starts then you can supply the value as a query parameter ("declare variable ... external"). You can also of course call a Java extension function which reads and returns the file contents as a string.

RE: Import data from flat files with XQuery - Added by Anonymous about 15 years ago

Legacy ID: #6605935 Legacy Poster: NickDiamond (nickdiamond_80)

Thank you. this is a good idea. Is there a possibility to choose different encodings in XQuery (to make sure that the received string is used correctly) ? But I think I have to avoid that right before the content gets to the xquery !?!

RE: Import data from flat files with XQuery - Added by Anonymous about 15 years ago

Legacy ID: #6606271 Legacy Poster: Michael Kay (mhkay)

Strings in XQuery are sequences of characters, not bytes. The translation from bytes to characters (which is where encodings come into play) is done outside the query.

RE: Import data from flat files with XQuery - Added by Anonymous about 15 years ago

Legacy ID: #6609151 Legacy Poster: David Lee (daldei)

slighltly off topic, but xmlsh can do this for you. xmlsh uses Saxon for xquery and comes with a conversion tool for converting plain text into XML. http://www.xmlsh.org example $ echo "A string" | csv2xml | xquery '//col' <col>A string</col> The encoding can be specified as arguments to csv2xml, or implicitly by the system property's file.encoding value. -David

    (1-4/4)

    Please register to reply