Do I really need to do all this just to get one item per line $ basex -s format=no -q 'doc("...")//.../*:name/concat(text(),"
")' AM 594 復興1 AM 612 中央 AM 630 台灣 AM 657 正聲 I use -s format=no to turn off spaces. -s format=text not much help. There really ought to be a -s option to say I want newlines instead of spaces. In perl all we need is perl -l. OK, maybe Windows users also need CRLFs (\r\n).
Do I really need to do all this just to get one item per line $ basex -s format=no -q 'doc("...")//.../*:name/concat(text(),"
")'
By default, there won't be any delimiting character between text nodes, which is why it wouldn't help to replace spaces with newlines. However, you may want to use the -w flag to preserve the original document whitespaces and newlines.
Christian
"CG" == Christian Grün christian.gruen@gmail.com writes:
CG> However, you may want to use the -w flag to preserve the original CG> document whitespaces and newlines.
I would have never guessed from the man page, which just mentions input, not output:
-w By default, whitespaces around text nodes are chopped when a database is created. The flag specifies to suppress chopping.
Nor is -w mentioned on http://docs.basex.org/wiki/Serialization
Yes it turns out -w is what I want.
$ basex -q 'doc("u.xml")' <W> <X>AA AA</X> <X>BB BB</X> <X>CC CC</X> <X>DD DD</X> </W>$ basex -q 'doc("u.xml")'; echo <-------note the echo needed to add the missing newline [BUG]. <W> <X>AA AA</X> <X>BB BB</X> <X>CC CC</X> <X>DD DD</X> </W> $ basex -w -s method=text -q 'doc("u.xml")'
AA AA BB BB CC CC DD DD $ basex -w -s method=text -q 'doc("u.xml")'|sed 's/^ +//;/^$/d' #OK, this is what I want. Thanks. AA AA BB BB CC CC DD DD
Wait, -w falls apart when just wanting the X nodes, $ basex -w -s method=text -q 'doc("u.xml")'
AA AA BB BB CC CC DD DD $ basex -w -s method=text -q 'doc("u.xml")//X'; echo AA AABB BBCC CCDD DD $
Last year's discussion https://mailman.uni-konstanz.de/pipermail/basex-talk/2010-October/000758.htm... Related discussion http://www.stylusstudio.com/xquerytalk/201012/003341.html
Anyways, proof that basex is "unfair":
$ basex -q 'doc("u.xml")/W'; echo <W> <X>AA AA</X> <X>BB BB</X> <X>CC CC</X> <X>DD DD</X> </W> $ basex -w -s method=text -q 'doc("u.xml")/W'; echo
AA AA BB BB CC CC DD DD
$ basex -q 'doc("u.xml")/W/X'; echo <X>AA AA</X> <X>BB BB</X> <X>CC CC</X> <X>DD DD</X> $ basex -w -s method=text -q 'doc("u.xml")/W/X'; echo AA AABB BBCC CCDD DD
Unfair!
basex-talk@mailman.uni-konstanz.de