Changes

Jump to navigation Jump to search
101 bytes added ,  13:34, 2 July 2020
no edit summary
BaseX provides two alternatives for parsing XML:
* By default, Java’s [httphttps://downloaddocs.oracle.com/en/java/javase/611/docs/api/java.xml/javax/xml/parsers/SAXParser.html SAXParser] is used to parse XML documents.
* The internal, built-in XML parser is more fault-tolerant than Java’s XML parser. It supports standard HTML entities out of the box, and it is faster than the default parser, in particular if small documents are to be parsed. However, the internal parser does not support the full range of DTD features and cannot resolve [[Catalog_Resolver|catalogs]].
The [[Database Module#db:add|db:add]] and [[Database Module#db:replace|db:replace]] 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>:
<pre classsyntaxhighlight lang="brush:xquery">
for $file in file:list("2Bimported")
return db:add('DB', $file, '', map { 'intparse': true() })
</presyntaxhighlight>
=HTML Parser=
An easy way to add TagSoup to your project is to follow this steps:
1. visit Visit [httphttps://mvnrepository.com/artifact/org.ccil.cowan.tagsoup/tagsoup/ MVN TagSoup Repository]
2. click Click on the version you want
3. on On the first tab, you can see an XML snippet like this:
<pre classsyntaxhighlight lang="brush:xml">
<dependency>
<groupId>org.ccil.cowan.tagsoup</groupId>
<version>1.2.1</version>
</dependency>
</presyntaxhighlight>
4. copy that in your own maven project’s <code>pom.xml</code> file into the <code><dependencies></code> element.
as function arguments:
<pre classsyntaxhighlight lang="brush:xquery">
fetch:xml("index.html", map {
'parser': 'html',
'htmlparser': map { 'html': false(), 'nodefaults': true() }
})
</presyntaxhighlight>
=JSON Parser=
the first lines as column headers:
<pre classsyntaxhighlight lang="brush:xquery">
for $file in file:list("2Bimported", false(), "*.csv")
return db:add("DB", $file, "", map {
'csvparser': map { 'header': true() }
})
</presyntaxhighlight>
=Text Parser=
Similar to the other formats, the text parser can also be specified via XQuery:
<pre classsyntaxhighlight lang="brush:xquery">
for $file in file:list("2Bimported", true(), "*.txt")
return db:add("DB", $file, "", map { 'parser': 'text' })
</presyntaxhighlight>
=Changelog=
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu