Re: Tool converts records to XML

"C. M. Sperberg-McQueen" <[email protected]>
Newsgroups gmane.text.xml.devel
Message-ID <[email protected]>
Hans-Juergen Rennau <[email protected]> writes:

> Roger, I would find it interesting to compare an awk solution with an
> XQuery one, also considering aspects like clarity and
> extensibility. Especially interesting as the potential of XQuery for
> tool building is by and large ignored.

Agreed!

> ...
>
> PS. Example of an XQuery-based solution:
>
> declare variable $uri external;
> declare variable $sep external := '&#x9;'; 
> <document>{
>     let $lines := unparsed-text-lines($uri)
>     let $names := $lines => head() => tokenize($sep)
>     for $line in tail($lines) return
>     <row>{
>         for $field at $pos in tokenize($line, $sep) return
>             element {$names[$pos]} {$field}
>     }</row>
> }</document>

This is good (and should work anywhere), but after spending a little
time on my own CSV parsing routines I realized that in BaseX, the
simplest thing to do is just to call

    csv:parse(unparsed-text($uri), map { 'header': 'yes'})

That is for comma-separated values; I think for tab-separated values one
would have to specify an additional option.

I don't have time to check, but I have a dim recollection that eXist
also has a function for reading CSV.

-- 
C. M. Sperberg-McQueen
Black Mesa Technologies LLC
http://blackmesatech.com

_______________________________________________________________________

XML-DEV is a publicly archived, unmoderated list hosted by OASIS
to support XML implementation and development. To minimize
spam in the archives, you must subscribe before posting.

[Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
Or unsubscribe: [email protected]
subscribe: [email protected]
List archive: http://lists.xml.org/archives/xml-dev/
List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.