Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Multiple XML Files with BaseX

Tags:

xml

basex

Hi I am new to BaseX and I am trying to read a bunch of XML files from a folder. After reading those files I will output the data into the database table (some RDBMS). But I am lost as to where to start as I am not able to find much tutorials about working with BaseX. I had searched on internet but still not much help. Can someone please help me with this.

Thanks in advance.

like image 378
user1188611 Avatar asked Jan 20 '13 19:01

user1188611


1 Answers

Use CREATE DB yourdbname /path/to/folder to create a database containing all documents in this folder. To access the documents, use collection("yourdbname"). If you need to access a particular file, use collection("yourdbname/document.xml").

To query all these files, you could do something like

for $document in collection("yourdbname")
return string-join((
    document-uri($document),
    ": ",
    xs:string(count($document//*))
  ))

which will return all document paths with their respecting node counts.

For further reading, have a look at the getting started section in BaseX' documentation, you should be able to find all needed information in there. For storing data in an RDBMS using SQL, have a look at the SQL module, there are also some examples included.

like image 83
Jens Erat Avatar answered Oct 27 '22 06:10

Jens Erat