Populating the baseX database with locally stored data is straight forward. But how would remote XML be fetched?
XQuery
The HTML Module provides a function for converting HTML to XML documents.
Documents can also be converted by specifying the parser and additional options in the query prolog:
declare option db:parser "html";
declare option db:htmlparser "html=false,nodefaults=true";
doc("index.html")
https://basex.readthedocs.io/en/search/Parsers/#xquery
To make concrete:
thufir@dur:~/basex$
thufir@dur:~/basex$ cat html_fetch_parse.xq
fetch:xml("http://books.toscrape.com/", map {
'parser': 'html',
'htmlparser': map { 'html': false(), 'nodefaults': true() }
})
thufir@dur:~/basex$
But what if the document is already XML?
HTML is fetched reasonably easily. Surely XML is even simpler.
fetch:xmldoes simply returns fetched nodes and it doesn't insert the nodes in any data base. As for simply loading XML, you can also use thedocfunction, e.g. usedoc('http://example.com/foo.xml'). To work with data bases from XQuery, see the module docs.basex.org/wiki/Database_Module, for instance docs.basex.org/wiki/Database_Module#db:add or docs.basex.org/wiki/Database_Module#db:create e.g.db:create("DB", doc('http://example.com/foo.xml'), 'foo.xml'). - Martin Honnen