benibela / xidel

Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
http://www.videlibri.de/xidel.html
GNU General Public License v3.0
681 stars 42 forks source link

Unknown namespace prefix: jnlib #28

Closed Reino17 closed 5 years ago

Reino17 commented 5 years ago

http://www.benibela.de/documentation/internettools/xpath-functions.html#modulejnlib:

In the Pascal Internet Tools library the unit xquery_json.pas needs to be loaded, before these functions are available.

Did you include this library in the binaries you supply, Benito? No matter what function I try, I constantly get Unknown namespace prefix: jnlib.

benibela commented 5 years ago

The library is there, but the namespace is not defined.

You can enable it with --xmlns:jnlib="http://jsoniq.org/function-library" (or any other prefix. only the url matters)

It is kind of deprecated with XPath/XQuery 3.1 coming

Reino17 commented 5 years ago

Ah, I see. I was looking at https://stackoverflow.com/q/54552141. Initially I had...

$ cat <<EOF | xidel -s - -e 'for $x in $json/conditional_ks return [$x() ! $x(.)()]'
{
  "conditional_ks": {
    "saturday": ["reportdata_by_type"],
    "sunday": ["rt_report", "metadata"]
  }
}
EOF

...return ["reportdata_by_type", "rt_report", "metadata"], but now I understand...

$ cat <<EOF | xidel -s - --xmlns:jnlib="http://jsoniq.org/function-library" -e '$json/[jnlib:values(conditional_ks)()]'
{
  "conditional_ks": {
    "saturday": ["reportdata_by_type"],
    "sunday": ["rt_report", "metadata"]
  }
}
EOF

...does the same.

I did a quick reading on XQuery 3.1. I understand it includes lots of json functions. Now I'm curious; how would this query look like when using XQuery 3.1?

benibela commented 5 years ago

?* gives on level of values, so

cat <<EOF | xidel -s - -e 'array{$json?*?*?*}'
{
  "conditional_ks": {
    "saturday": ["reportdata_by_type"],
    "sunday": ["rt_report", "metadata"]
  }
}
EOF
Reino17 commented 5 years ago

Thank you.