How to run XQuery script on XML files with explicit schema info using xqilla?

1.4k Views Asked by At

How to run XQuery script on XML files with explicit schema info using xqilla?

I'm using xqilla to run XQuery scripts on XML files:

$ more BookstoreQ.xml
<?xml version="1.0" ?>
<!-- schema info
<!DOCTYPE Bookstore [
   <!ELEMENT Bookstore (Book | Magazine)*>
   <!ELEMENT Book (Title, Authors, Remark?)>
   <!ATTLIST Book ISBN CDATA #REQUIRED
                  Price CDATA #REQUIRED
                  Edition CDATA #IMPLIED>
   <!ELEMENT Magazine (Title)>
   <!ATTLIST Magazine Month CDATA #REQUIRED Year CDATA #REQUIRED> 
   <!ELEMENT Title (#PCDATA)>
   <!ELEMENT Authors (Author+)>
   <!ELEMENT Remark (#PCDATA)>
   <!ELEMENT Author (First_Name, Last_Name)>
   <!ELEMENT First_Name (#PCDATA)>
   <!ELEMENT Last_Name (#PCDATA)>
]>
-->
<Bookstore>
   <Book ISBN="ISBN-0-13-713526-2" Price="85" Edition="3rd">
      <Title>A First Course in Database Systems</Title>
      <Authors>
         <Author>
            <First_Name>Jeffrey</First_Name>
            <Last_Name>Ullman</Last_Name>
         </Author>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
   </Book>
   <Book ISBN="ISBN-0-13-815504-6" Price="100">
      <Title>Database Systems: The Complete Book</Title>
      <Authors>
         <Author>
            <First_Name>Hector</First_Name>
            <Last_Name>Garcia-Molina</Last_Name>
         </Author>
         <Author>
            <First_Name>Jeffrey</First_Name>
            <Last_Name>Ullman</Last_Name>
         </Author>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
      <Remark>
         Buy this book bundled with "A First Course" - a great deal!
      </Remark>
   </Book>
   <Book ISBN="ISBN-0-11-222222-3" Price="50">
      <Title>Hector and Jeff's Database Hints</Title>
      <Authors>
         <Author>
            <First_Name>Jeffrey</First_Name>
            <Last_Name>Ullman</Last_Name>
         </Author>
         <Author>
            <First_Name>Hector</First_Name>
            <Last_Name>Garcia-Molina</Last_Name>
         </Author>
      </Authors>
      <Remark>An indispensible companion to your textbook</Remark>
   </Book>
   <Book ISBN="ISBN-9-88-777777-6" Price="25">
      <Title>Jennifer's Economical Database Hints</Title>
      <Authors>
         <Author>
            <First_Name>Jennifer</First_Name>
            <Last_Name>Widom</Last_Name>
         </Author>
      </Authors>
   </Book>
   <Magazine Month="January" Year="2009">
       <Title>National Geographic</Title>
   </Magazine>
   <Magazine Month="February" Year="2009">
       <Title>National Geographic</Title>
   </Magazine>
   <Magazine Month="February" Year="2009">
       <Title>Newsweek</Title>
   </Magazine>
   <Magazine Month="March" Year="2009">
       <Title>Hector and Jeff's Database Hints</Title>
   </Magazine>
</Bookstore>

$more query
let $doc := .
for $node in $doc/Bookstore/*
where $node/@Price < 90 and $node/Authors/Author/Last_Name = "Ullman"
return $node/Title

$ xqilla -i ../BookstoreQ.xml query
<Title>A First Course in Database Systems</Title>
<Title>Hector and Jeff's Database Hints</Title>

The above doesn't work as soon as I uncomment the schema block of code in BookstoreQ.xml:

$ xqilla -i BookstoreQ.xml query
:0:0: error: Error parsing resource: file:///Users/user121/BookstoreQ.xml. Error message: internal subset is not allowed when reusing the grammar [err:FODC0002]

Is there a way to fix this?

What are some alternative XQuery tools that have CLI?

0

There are 0 best solutions below