by cnity · 6y ago · 0 comments
npm list --json | ({ json }) => json.somePackage.author.name
What if it allowed parsing of XML natively, allowing instant scrapers to be written in a single command?
curl www.example.com | ({ xml }) => xml.find('.importantInformation') > scraped_info.txt
[0] https://github.com/kellyjonbrazil/jc
(disclaimer: I am the author)
> What if it allowed parsing of XML natively, allowing instant scrapers to be written in a single command?
Powershell’s Invoke-RestMethod parses xml natively to a structured output; it’s useful but not enough to make XML fun or trivial to work with beyond root.node.foo.title simple scraping.
What I meant by this is that the newline character is the primary delimiter of the data, but I take your point. IMO, the best way to tackle the myriad ways of structuring data is to write parsers for them, not to rewrite the programs themselves to work with your shell's idea of structured data. That's a losing battle.
[0] with a hex editor it is possible to create a file system entry using '/' in its name. Linux does not handle this situation with grace.
I think that’s a losing battle as well due to the brittle nature, any tweak to any command output could break something, meaning endless maintenance work on a large scale.
Rewriting concepts into new commands at least bring consistency and a chance of shrinking maintenance work as it settles on a nice design - and if not the maintenance won’t be endless rebuilds of the same parsers.
[0] https://github.com/kellyjonbrazil/jc
(disclaimer: I am the author)
I'm not sure about similar xml cli tools, but they probably exist.
Point is, both of these should be cli tools, not shell built-ins.
I :heart: xmlstarlet (sometimes installed as that name, sometimes as just "xml"): https://formulae.brew.sh/formula/xmlstarlet#default => https://xmlstar.sourceforge.io/
The xsltproc that ships with libxslt1 is also pretty handy, although more verbose
While not quite xml, pup is super handy for doing quick html selections: https://formulae.brew.sh/formula/pup#default => https://github.com/EricChiang/pup#readme
xsltproc of course