Reading multiple XML files with BaseX

Hi I'm new to BaseX and I'm trying to read a bunch of XML files from a folder. After reading these files, I will output the data to a database table (some RDBMS). But I lost out on where to start as I can't find many tutorials on working with BaseX. I searched the internet but still didn't help much. Can someone please help me with this.

Thanks in advance.

+3


source to share


1 answer


Use CREATE DB yourdbname /path/to/folder

to create a database containing all documents in this folder. To access documents , use collection("yourdbname")

. If you need access to a specific file, use collection("yourdbname/document.xml")

.

To request all of these files, you can 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 respectful node counts.

For further reading take a look at BaseX's getting started section , you should be able to find all the information you need. For storing data in DBMS using SQL see SQL module , there are also some examples.

+4


source







All Articles