Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active December 30, 2015 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fancellu/7815238 to your computer and use it in GitHub Desktop.
Save fancellu/7815238 to your computer and use it in GitHub Desktop.
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()
}
1
2
3
4
<root>
<child>John</child>
<child>Mary</child>
</root>
<root2>Another one</root2>
<?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>
@ChristianGruen
Copy link

One remark: You can address all documents of the currently opened database by starting your query with /.

@fancellu
Copy link
Author

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