The {{Function|Database|db:add}} and {{Function|Database|db:put}} functions can also be used to add new XML documents to the database. The following example query uses the internal XML parser and adds all files to the database <code>DB</code> that are found in the directory <code>2Bimported</code>:
<syntaxhighlight pre lang="'xquery"'>
for $file in file:list("2Bimported")
return db:add('DB', $file, '', map { 'intparse': true() })
</syntaxhighlightpre>
=HTML Parser=
==Installation==
====Downloads====
TagSoup is already included in the full BaseX distributions ({{Code|BaseX.zip}}, {{Code|BaseX.exe}}, etc.). It can also be manually downloaded and embedded on the appropriate platforms.
====Maven====
An easy way to add TagSoup to your project is to as follows:
3. On the first tab, you can see an XML snippet like this:
<syntaxhighlight pre lang="xml">
<dependency>
<groupId>org.ccil.cowan.tagsoup</groupId>
<version>1.2.1</version>
</dependency>
</syntaxhighlightpre>
4. Insert the XML fragment into the <code><dependencies></code> element of your project’s <code>pom.xml</code> file.
====Debian====
With Debian, TagSoup will automatically be detected and included after it has been installed via:
* '''reuse''', '''help''': not supported.
===GUI===
Go to Menu ''Database'' → ''New'' and select "HTML" in the input format combo box.There's an info in the "Parsing" tab about whether TagSoup is available or not. Thesame applies to the "Resources" tab in the "Database Properties" dialog.
These two dialogs come with an input field 'Parameters' where TagSoup optionscan be entered. Keys and values are separated by the equal sign, multiple options are separated by commas, e.g.: <code>method=xml,nons=true</code>.
===Command Line===
Turn on the HTML Parser before parsing documents, set a file filter and optional parsing options:
SET {{Option|HTMLPARSER}} method=xml,nons=true
===XQuery===
The [[HTML Module]] provides XQuery functions for converting HTML to XML documents.In addition, all functions that accept [[Options#Parsing|Parsing Options]] can be used as well to convert HTML:
In addition, all functions that accept [[Options#Parsing|Parsing Options]] can be used as well to convert HTML: <syntaxhighlight pre lang="'xquery"'>
fetch:doc("index.html", map {
'parser': 'html',
'htmlparser': map { 'htmlmethod': false()'xml', 'nodefaultsnons': true() }
})
</syntaxhighlightpre>
=JSON Parser=
With BaseX can also import , JSON documentscan be imported. The resulting format is JSON parsing options are described in the documentation for of the XQuery [[JSON Module]]:.
==GUI==
Go to Menu ''Database'' → ''New'' and select "JSON" in the input format combo box.You can set the following options for parsing JSON documents in the "Parsing" tab: * '''Encoding''': Choose the appropriate encoding of the JSON file.* '''JsonML''': Activate this option if the incoming file is a JsonML file.
==Command Line==
==XQuery==
The [[JSON Module]] provides functions for converting JSON objects to XML documents. In addition, all functions that accept [[Options#Parsing|Parsing Options]] can be used as well to convert JSON. The following query converts a JSON string to an XML document, using the conversion format {{Code|[[JSON Module#Basic|basic]]}}: <pre lang='xquery'>db:create('json-db', '{ "key": "value" }', 'example.json', map { 'parser': 'json', 'jsonparser': map { 'format': 'basic' }})</pre>
=CSV Parser=
BaseX can be used to import CSV documents. Different alternatives how to proceed The CSV parsing options are shown described in the following:documentation of the [[CSV Module]].
==GUI==
Go to Menu ''Database'' → ''New'' and select "CSV" in the input format combo box.
You can set the following options for parsing CSV documents in the "Parsing" tab: * '''Encoding''': Choose the appropriate encoding of the CSV file.* '''Separator''': Choose the column separator of the CSV file. Possible: <code>comma</code>, <code>semicolon</code>, <code>tab</code> or <code>space</code> or an arbitrary character.* '''Header''': Activate this option if the incoming CSV files have a header line.
==Command Line==
==XQuery==
The [[CSV Module]] provides a function for converting CSV to XML documents.
Documents In addition, all functions that accept [[Options#Parsing|Parsing Options]] can also be converted by specifying used as well to convert CSV. In the parser in an XQuery function.The following example query adds , all CSV files that from a directory are located in thedirectory {{Code|2Bimported}} added to the a database {{Code|DB}} and interprets, with the first lines line of each file interpreted as column headersheader:
<syntaxhighlight pre lang="'xquery"'>
for $file in file:list("2Bimported", false(), "*.csv")
return db:add("DBcsv-db", $file, "", map {
'parser': 'csv',
'csvparser': map { 'header': true() }
})
</syntaxhighlightpre>
=Changelog=
;Version 7.8
* Updated: parser options
;Version 7.7.2
* Removed: CSV option "format"
;Version 7.3
* Updated: the CSV {{Code|SEPARATOR}} option may now be assigned arbitrary single characters
;Version 7.2
* Updated: Enhanced support for TagSoup options