Last active
December 30, 2015 10:19
-
-
Save fancellu/7815238 to your computer and use it in GitHub Desktop.
BaseX XQJ 1.3 embedded example with XQS Now uses DEFAULTDB option
https://github.com/BaseXdb/basex/issues/821 https://github.com/fancellu/xqs
http://xqj.net/basex/
http://basex.org/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.felstar.xqs.example | |
import com.felstar.xqs.XQS._ | |
import com.felstar.xqs.XQS.AllImplicits._ | |
import xml.PrettyPrinter | |
import com.xqj2.XQConnection2 | |
object BaseXEmbeddedXQS extends App { | |
val conn = new net.xqj.basex.local.BaseXXQDataSource().getConnection.asInstanceOf[XQConnection2] | |
val strings: Seq[String] = conn("1 to 4") | |
strings.foreach(println) | |
val xqe = conn.createExpression() | |
val db="xmlstore" | |
xqe.executeCommand(s"CHECK $db") | |
xqe.executeCommand("SET DEFAULTDB true") | |
{ | |
val sampleXML= <root> | |
<child>John</child> | |
<child>Mary</child> | |
</root> | |
val item=conn.createItemFromNode(sampleXML, null) | |
conn.insertItem("sampleXML.xml",item,null) | |
} | |
{ | |
val item=conn.createItemFromNode( <root2>Another one</root2>, null) | |
conn.insertItem("sampleXML2.xml",item,null) | |
} | |
val elems:Seq[scala.xml.Elem] = conn("doc('sampleXML.xml'),doc('sampleXML2.xml')") | |
val pp=new PrettyPrinter(80,2) | |
elems foreach(x=>println(pp.format(x))) | |
conn.close() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 | |
2 | |
3 | |
4 | |
<root> | |
<child>John</child> | |
<child>Mary</child> | |
</root> | |
<root2>Another one</root2> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='UTF-8'?> | |
<project | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | |
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.felstar</groupId> | |
<artifactId>basex-xqs-example</artifactId> | |
<packaging>jar</packaging> | |
<version>0.0.1</version> | |
<build> | |
<finalName>scalatra-maven-prototype</finalName> | |
<sourceDirectory>src/main/scala</sourceDirectory> | |
<testSourceDirectory>src/test/scala</testSourceDirectory> | |
<plugins> | |
<plugin> | |
<groupId>net.alchim31.maven</groupId> | |
<artifactId>scala-maven-plugin</artifactId> | |
<version>3.1.6</version> | |
<executions> | |
<execution> | |
<goals> | |
<goal>compile</goal> | |
<goal>testCompile</goal> | |
</goals> | |
<configuration> | |
<args> | |
<arg>-make:transitive</arg> | |
<arg>-dependencyfile</arg> | |
<arg>${project.build.directory}/.scala_dependencies</arg> | |
</args> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
<dependencies> | |
<dependency> | |
<groupId>org.scala-lang</groupId> | |
<artifactId>scala-library</artifactId> | |
<version>2.10.3</version> | |
<scope>compile</scope> | |
</dependency> | |
<dependency> | |
<groupId>net.xqj</groupId> | |
<artifactId>basex-xqj</artifactId> | |
<version>1.3.0-SNAPSHOT</version> | |
</dependency> | |
<dependency> | |
<groupId>org.basex</groupId> | |
<artifactId>basex</artifactId> | |
<version>7.8-SNAPSHOT</version> | |
</dependency> | |
</dependencies> | |
<repositories> | |
<repository> | |
<id>basex</id> | |
<name>BaseX Maven Repository</name> | |
<url>http://files.basex.org/maven</url> | |
</repository> | |
<repository> | |
<id>xqj.net</id> | |
<name>XQJ.NET Maven Repository</name> | |
<url>http://xqj.net/maven</url> | |
</repository> | |
</repositories> | |
</project> |
Yes, I know, was just making it explicit.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One remark: You can address all documents of the currently opened database by starting your query with
/
.