This query selects all the book titles from bookstore.xml:
java com.sybase.xml.xql.XqlDriver -qstring "/bookstore/book/title"
-infile bookstore.xml Query returned true and the result is <xql_result> <title>Seven Years in Trenton</title> <title>History of Trenton</title> <title>Trenton Today, Trenton Tomorrow</title> </xql_result>
This example lists all the author’s first names from bookstore.xml. XQL uses a zero-based numbering system; that is, “0” specifies the first occurrence of an element in a file.
java com.sybase.xml.xql.XqlDriver
-qstring "/bookstore/book/author/first-name[0]"
-infile bookstore.xml Query returned true and the result is <xql_result> <first-name>Joe</first-name> <first-name>Mary</first-name> <first-name>Toni</first-name> </xql_result>
The following example lists all the authors in bookstore.xml whose last name is “Bob”:
java com.sybase.xml.xql.XqlDriver
-qstring "/bookstore/book/author[last-name='Bob']"
-infile bookstore.xmlQuery returned true and the result is <xql_result> <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> </xql_result>