[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Tool converts records to XML

  • From: "C. M. Sperberg-McQueen" <cmsmcq@blackmesatech.com>
  • To: Hans-Juergen Rennau <hrennau@yahoo.de>
  • Date: Tue, 15 Nov 2022 07:49:33 -0700

Re:  Tool converts records to XML
Hans-Juergen Rennau <hrennau@yahoo.de> 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


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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