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
674 stars 42 forks source link

Add examples/ directory #98

Open ctrlcctrlv opened 1 year ago

ctrlcctrlv commented 1 year ago

Promised in main README. Hopefully the beginning of many examples that don't require network connectivity.

Reino17 commented 1 year ago

xquery version "3.1"; [...] parse-xml('<html>...</html>')

xquery version "3.1-xidel"; [...] parse-html('<html>...</html>') (parse-html())

xidel --html --xquery3="$(cat examples/1.xq)"

There's --extract-file or -e @ for that, and --output-node-indent for some prettification:

xidel -s --extract-file="examples/1.xq" --output-format=html --output-node-indent
xidel -s -e @"examples/1.xq" --output-format=html --output-node-indent
<!DOCTYPE html>
<table>
  <tbody>
    <tr class="C_123 hascol1" id="123">
      <td>123</td>
      <!--  -->
    </tr>
    <tr class="C_456 C_other hascol1 hascomment" id="456">
      <td>456</td>
      <!-- other -->
    </tr>
    <tr class="C_foo C_columns hascol1 hascomment" id="foo">
      <td>foo</td>
      <!-- columns -->
    </tr>
    <tr class="C_bar C_are hascol1 hascomment" id="bar">
      <td>bar</td>
      <!-- are -->
    </tr>
    <tr class="C_xyz C_ignored C_zomg hascol1 hascomment zomg" id="xyz">
      <td name="zomg">xyz</td>
      <!-- ignored -->
    </tr>
  </tbody>
</table>

However, I think the wiki is a much better place for examples. It's still on my long to-do-list. And let's then start off with some easy examples first, because let's face it, this particular example is really for the advanced Xidel-user.