XQL-Patternsuche mittels Perlmodul XML::XQL

Beispiel-Dokument bookstore.html

Suche nach Elementen

'/bookstore/book/title' bookstore.xml

<title>Seven Years in Trenton</title>
<title>History of Trenton</title>

'/bookstore/magazine/title' bookstore.xml

<title>Tracking Trenton</title>

'/bookstore/*/title' bookstore.xml

<title>Seven Years in Trenton</title>
<title>History of Trenton</title>
<title>Tracking Trenton</title>

'/bookstore/book/author' bookstore.xml

<author>
      <first-name>Joe</first-name>
      <last-name>Bob</last-name>
      <award>Trenton Literary Review Honorable Mention</award>
    </author>
<author>
      <first-name>Mary</first-name>
      <last-name>Bob</last-name>
      <publication>
        Selected Short Stories of
        <first-name>Mary</first-name> <last-name>Bob</last-name>
      </publication>
    </author>
<author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>

'/bookstore/book/author/*' bookstore.xml

<first-name>Joe</first-name>
<last-name>Bob</last-name>
<award>Trenton Literary Review Honorable Mention</award>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
<publication>
        Selected Short Stories of
        <first-name>Mary</first-name> <last-name>Bob</last-name>
      </publication>
<first-name>Toni</first-name>
<last-name>Bob</last-name>
<degree from="Trenton U">B.A.</degree>
<degree from="Harvard">Ph.D.</degree>
<award>Pulizer</award>
<publication>Still in Trenton</publication>
<publication>Trenton Forever</publication>

'/bookstore/book/price' bookstore.xml

<price>12</price>
<price>55</price>
<price intl="canada" exchange="0.7">6.50</price>

'/bookstore/book/price/@exchange' bookstore.xml

exchange="0.7"

Anwendung von Filtern

'/bookstore/book/author' bookstore.xml

<author>
      <first-name>Joe</first-name>
      <last-name>Bob</last-name>
      <award>Trenton Literary Review Honorable Mention</award>
    </author>
<author>
      <first-name>Mary</first-name>
      <last-name>Bob</last-name>
      <publication>
        Selected Short Stories of
        <first-name>Mary</first-name> <last-name>Bob</last-name>
      </publication>
    </author>
<author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>

'/bookstore/book/author[award]' bookstore.xml

<author>
      <first-name>Joe</first-name>
      <last-name>Bob</last-name>
      <award>Trenton Literary Review Honorable Mention</award>
    </author>
<author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>

'/bookstore/book[excerpt]/author[award]' bookstore.xml

<author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>

'/bookstore/book[excerpt][title]' bookstore.xml

<book style="novel" id="myfave">
    <title>Trenton Today, Trenton Tomorrow</title>
    <author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>
    <price intl="canada" exchange="0.7">6.50</price>
    <excerpt>
      <p>It was a dark and stormy night.</p>
      <p>But then all nights in Trenton seem dark and
      stormy to someone who has gone through what
      <emph>I</emph> have.</p>
      <definition-list>
        <term>Trenton</term>
        <definition>misery</definition>
      </definition-list>
    </excerpt>
  </book>

'/bookstore/book[author/degree]/title' bookstore.xml

<title>Trenton Today, Trenton Tomorrow</title>

'/bookstore/book[author/publication]/title' bookstore.xml

<title>History of Trenton</title>
<title>Trenton Today, Trenton Tomorrow</title>

Anwendung Boolescher Operatoren

'/bookstore/book[author/publication $and$ author/degree]/title' bookstore.xml

<title>Trenton Today, Trenton Tomorrow</title>

'/bookstore/book[author/publication $or$ author/degree]/title' bookstore.xml

<title>History of Trenton</title>
<title>Trenton Today, Trenton Tomorrow</title>

Equivalenz

'/bookstore/book/@style' bookstore.xml

style="autobiography"
style="textbook"
style="novel"

'/bookstore/book/@style[. > "av"]' bookstore.xml

style="textbook"
style="novel"

'//book[/bookstore/@specialty = @style]' bookstore.xml

<book style="novel" id="myfave">
    <title>Trenton Today, Trenton Tomorrow</title>
    <author>
      <first-name>Toni</first-name>
      <last-name>Bob</last-name>
      <degree from="Trenton U">B.A.</degree>
      <degree from="Harvard">Ph.D.</degree>
      <award>Pulizer</award>
      <publication>Still in Trenton</publication>
      <publication>Trenton Forever</publication>
    </author>
    <price intl="canada" exchange="0.7">6.50</price>
    <excerpt>
      <p>It was a dark and stormy night.</p>
      <p>But then all nights in Trenton seem dark and
      stormy to someone who has gone through what
      <emph>I</emph> have.</p>
      <definition-list>
        <term>Trenton</term>
        <definition>misery</definition>
      </definition-list>
    </excerpt>
  </book>

Anwendung von Methoden

'/bookstore/book/title' bookstore.xml

<title>Seven Years in Trenton</title>
<title>History of Trenton</title>
<title>Trenton Today, Trenton Tomorrow</title>

'/bookstore/book/title[value() < "S"]' bookstore.xml

<title>History of Trenton</title>

'/bookstore/book[index()=0]/title' bookstore.xml

<title>Seven Years in Trenton</title>

'/bookstore/book[end()]/title' bookstore.xml

<title>Trenton Today, Trenton Tomorrow</title>

Anwendung einer Union

'/bookstore/book/(author/last-name | author/first-name $union$ title)' bookstore.xml

<title>Seven Years in Trenton</title>
<first-name>Joe</first-name>
<last-name>Bob</last-name>
<title>History of Trenton</title>
<first-name>Mary</first-name>
<last-name>Bob</last-name>
<title>Trenton Today, Trenton Tomorrow</title>
<first-name>Toni</first-name>
<last-name>Bob</last-name>