Show HN: Xq – command-line XML and HTML beautifier and content extractor
11–20 of 36 posts
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#12Looks good! Does the xpath expression support XML namespaces?
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#13Looks good! Does the xpath expression support XML namespaces?
No, and arguably worse: it completely ignores them $ echo ' hello ' | xq --xpath '/a/b/text()' hello Only partial support for functions, too, it would appear $ echo ' hello ' | xq --xpath 'count(/a/*)' $ Some A++ error handling, too, as it just calls panic when angry
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#14Earlier quoted context omitted.
Thank you for your support! I didn't consider CSS selectors as an alternative to Xpath, but really like the idea. Absolutely agree CSS selectors will be more convenient :)
The issue with CSS selectors is they can only express element selection. There's no concept of picking the text of the element or the value of an attribute. There's been proposals over the years to support pseudo elements for that, so you could make something up like ::attr(name) and ::text, but nothing in the standards. htmlq does this by having various command line options like --attribute and --text. https://githu…
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#15Shoutout to my go-to: https://github.com/EricChiang/pup#readme (also golang) and my 2nd favorite https://xmlstar.sourceforge.net/
xq looks interesting for pure XML, will add it to my notes.
Regarding xmlstarlet, I don't use it much but here's some stuff from my notes:
XML filter on xpath: xmlstarlet sel -t -c configuration/appender logback.xml; echo
XML editing: xmlstarlet ed -d configuration/root -d configuration/logger -s configuration -t elem -n woof -v 'Woof!' logback.xml
The last one deletes elements given by xpath "configuration/root" and "configuration/logger", then adds a new element with the contents Woof! under the xpath "configuration".
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#16Shoutout to my go-to: https://github.com/EricChiang/pup#readme (also golang) and my 2nd favorite https://xmlstar.sourceforge.net/
Definitely seconding pup, love it and it's easy to use with css selectors. Often use it to parse HTML tables of data on random websites into usable CSVs / etc. xq looks interesting for pure XML, will add it to my notes. Regarding xmlstarlet, I don't use it much but here's some stuff from my notes: XML filter on xpath: xmlstarlet sel -t -c configuration/appender logback.xml; echo XML editing: xmlstarlet ed -d configur…
It is also handy doing at some PoC work, and then one can feed it "-C" to output the backing xslt for use elsewhere
$ echo 'hello' | xmlstarlet sel -t -m /a -c 'count(*)' --nl
1
$ echo 'hello' | xmlstarlet sel -C -t -m /a -c 'count(*)' --nl
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#17xsltproc
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#18Earlier quoted context omitted.
No, and arguably worse: it completely ignores them $ echo ' hello ' | xq --xpath '/a/b/text()' hello Only partial support for functions, too, it would appear $ echo ' hello ' | xq --xpath 'count(/a/*)' $ Some A++ error handling, too, as it just calls panic when angry
Ah ok; Namespace support before XPath 3.0 with Q{nsname}localname would make cli tool like this a bit too verbose. Of course you could store ns-prefix to ns mappings to conf file or environment variables...
$ echo 'hello' | xq --xpath '/Q{urn:alpha}a/text()'
panic: /Q{urn:alpha}a/text() has an invalid token.
goroutine 18 [running]:
github.com/antchfx/xmlquery.Find(...)
github.com/antchfx/xmlquery@v1.3.8/query.go:76
...
It seems to be a problem with that backing xmlquery library, and I did a quick GitHub topics search and found https://github.com/zzossig/rabbit which claimed to be XPath 3, but then https://github.com/zzossig/rabbit#what-is-not-supported says "lol, namespaces, wat?" so :-(Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#19Earlier quoted context omitted.
Ah ok; Namespace support before XPath 3.0 with Q{nsname}localname would make cli tool like this a bit too verbose. Of course you could store ns-prefix to ns mappings to conf file or environment variables...
I actually tried the lxml syntax "/{urn:beta}b" and that's how I learned about the panic-based error handling, but I didn't know about that Q syntax, so thank you for bringing it to my attention $ echo ' hello ' | xq --xpath '/Q{urn:alpha}a/text()' panic: /Q{urn:alpha}a/text() has an invalid token. goroutine 18 [running]: github.com/antchfx/xmlquery.Find(...) github.com/antchfx/xmlquery@v1.3.8/query.go:76 ... It seem…
Re: Show HN: Xq – command-line XML and HTML beautifier and content extractor
#20 https://ap-playerservices.streamtheworld.com/api/livestream?station=NOVA_919&version=1.9
so xqilla and learning xlst et al still seems like my to-go for complex documents