Use of BaseX
Hi, I am new to BaseX and documentation is also not very helpful for me. I am trying to deal with a collection of XML files present on the server. I am able to access those files using REST .
What I want to do is read those XML files from a collection present in a certain folder and using Xpath/Xquery get certain nodes from these files and populate a RDBMS corresponding to them.
For example: > bookstore < > book < abc >/ book < > price < 123 > /title < > title < xyz > /title < > /book <
I have 10 of these files in my collection. So my question is how can I query all these Xml files at ones and get specific results like "Books with price value greater than 100". Once I get these results I want to store the result in a RDBMS so that at later point I can query that RDBMS to generate certain reports.
NOTE: I am a graduate student and just doing this for learning and academic purpose.
Hope to hear from someone soon.
Quoted text · Ankur Kasliwal · 3 lines
> I have 10 of these files in my collection. So my question is how can I query > all these Xml files at ones and get specific results like "Books with price > value greater than 100".
Use a simple XPath expression [1], such as
collection("name-of-collection"//Books[Price > 100]
You mentioned our REST service, which can also be used for that [2]:
http://localhost:8984/rest/name-of-collection?query=//Books...
Quoted text · Ankur Kasliwal · 3 lines
> Once I get these results I want to store the result > in a RDBMS so that at later point I can query that RDBMS to generate certain > reports.
Check out the SQL Module of our documentation [3] and give it a try.
Regards, Christian
[1] http://www.w3schools.com/xpath/ [2] http://docs.basex.org/wiki/REST [3] http://docs.basex.org/wiki/SQL
Dear Ankur, try :
for $book in /bookstore/book
where $book/author = 'ABC'
order by $book/title
return
$bookThere are many XQuery tutorials available on the web, http://www.w3schools.com/xquery/default.asp for example, if you like the bookstore use case !
Be careful with BaseX, you may become addicted to XQuery ;-)
Regards, Fabrice
Quoted text · Ankur Kasliwal · 47 lines
De : basex-talk-bounces at mailman.uni-konstanz.de [mailto:basex-talk-bounces at mailman.uni-konstanz.de] De la part de Ankur Kasliwal Envoyé : lundi 21 janvier 2013 17:19 À : Christian Grün Cc : BaseX Objet : Re: [basex-talk] Use of BaseX I did some work and try to avoid using the RDBMS part. So here is my question again If I have 100 XML files with structure as : <bookstore> <book> <title>Learn XML</title> <author>ABC</author> </book> <book> <title>Learn Java</title> <author>PQR</author> </book> ------- ------- { more such book elements} </bookstore> So if I want to directly write query like " All books authored by "ABC" sorted by name of book" on the collection of 100 XML files. Is there anyway of doing this with Xquery/Xpath. Can someone provide me steps and a query for doing that. Also one more question as BaseX is a database for XML but I am not actually able to figure out its real advantages over databases available. Is its interface or functionality or anything else which is better than other databases. Thank you in advance and hope to hear from you soon. -- Ankur On Mon, Jan 21, 2013 at 4:43 AM, Christian Grün <christian.gruen at gmail.com<mailto:christian.gruen at gmail.com>> wrote: > I have 10 of these files in my collection. So my question is how can I query > all these Xml files at ones and get specific results like "Books with price > value greater than 100". Use a simple XPath expression [1], such as collection("name-of-collection"//Books[Price > 100] You mentioned our REST service, which can also be used for that [2]: http://localhost:8984/rest/name-of-collection?query=//Books... > Once I get these results I want to store the result > in a RDBMS so that at later point I can query that RDBMS to generate certain > reports. Check out the SQL Module of our documentation [3] and give it a try. Regards, Christian [1] http://www.w3schools.com/xpath/ [2] http://docs.basex.org/wiki/REST [3] http://docs.basex.org/wiki/SQL -- Sincerely, Ankur Kasliwal MS in CS, Northeastern University ankur.kasliwal.26 at gmail.com<mailto:ankur.kasliwal.26 at gmail.com> (916)-673-7559
I did some work and try to avoid using the RDBMS part. So here is my question again
If I have 100 XML files with structure as :
<bookstore>
<book>
<title>Learn XML</title>
<author>ABC</author>
</book>
<book>
<title>Learn Java</title>
<author>PQR</author>
</book>
-------
------- { more such book elements}
</bookstore>So if I want to directly write query like " All books authored by "ABC" sorted by name of book" on the collection of 100 XML files. Is there anyway of doing this with Xquery/Xpath. Can someone provide me steps and a query for doing that.
Also one more question as BaseX is a database for XML but I am not actually able to figure out its real advantages over databases available. Is its interface or functionality or anything else which is better than other databases.
Thank you in advance and hope to hear from you soon.
Quoted text · Christian Grün · 28 lines
> > I have 10 of these files in my collection. So my question is how can I > query > > all these Xml files at ones and get specific results like "Books with > price > > value greater than 100". > > Use a simple XPath expression [1], such as > > collection("name-of-collection"//Books[Price > 100] > > You mentioned our REST service, which can also be used for that [2]: > > http://localhost:8984/rest/name-of-collection?query=//Books... > > > Once I get these results I want to store the result > > in a RDBMS so that at later point I can query that RDBMS to generate > certain > > reports. > > Check out the SQL Module of our documentation [3] and give it a try. > > Regards, > Christian > > [1] http://www.w3schools.com/xpath/ > [2] http://docs.basex.org/wiki/REST > [3] http://docs.basex.org/wiki/SQL >
Written for BaseX 7.5. BaseX may have changed since: please check the current documentation.