Scripting and security

Operating Systems, software development, scripting, PowerShell tips, network and security

Menú principal
  • Categorías
  • Cursos
  • Libro de PowerShell
  • Lo mejor
  • Lo último
  • Proyectos
  • Contactar
Ir al contenido

Usar XML:DB API para ejecutar una consulta de base de datos con XQuery en el servidor eXist-db

Ofertas y promociones en Videojuegos

Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import org.exist.xmldb.EXistResource;
 
public class XQueryExample {
 
private static String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";
 
/**
* args[0] Should be the name of the collection to access
* args[1] Should be the XQuery to execute
*/
public static void main(String args[]) throws Exception {
 
final String driver = "org.exist.xmldb.DatabaseImpl";
 
// initialize database driver
Class cl = Class.forName(driver);
Database database = (Database) cl.newInstance();
database.setProperty("create-database", "true");
DatabaseManager.registerDatabase(database);
 
Collection col = null;
try {
col = DatabaseManager.getCollection("xmldb:exist://localhost:8080/exist/xmlrpc/db/");
XQueryService xqs = (XQueryService) col.getService("XQueryService", "1.0");
xqs.setProperty("indent", "yes");
 
CompiledExpression compiled = xqs.compile("doc(\"/profesores.xml\")/profesores/profesor/nombre\n");
ResourceSet result = xqs.execute(compiled);
ResourceIterator i = result.getIterator();
Resource res = null;
while(i.hasMoreResources()) {
try {
res = i.nextResource();
System.out.println(res.getContent());
} finally {
//dont forget to cleanup resources
try { ((EXistResource)res).freeResources(); } catch(XMLDBException xe) {xe.printStackTrace();}
}
}
} finally {
//dont forget to cleanup
if(col != null) {
try { col.close(); } catch(XMLDBException xe) {xe.printStackTrace();}
}
}
}
}

CATEGORÍAS

Java

ETIQUETAS

Access, eXist-db, Jesús Niño, Jesús Niño Camazón, Modules, System.out.println, XML

MÁS

  • Instalación de gestores de contenidos (Implantación de aplicaciones web)
  • Ejercicios de PowerShell: crear mediante scripts una estructura de una red con un dominio y las configuraciones de GPOS que necesites
  • Programación de documentos Web utilizando lenguajes de «script» de servidor (Implantación de aplicaciones web)
  • Mostrar un documento del servidor eXist-db y se imprime en la salida estándar
  • Usar XML:DB API para ejecutar una consulta de base de datos con XPath en el servidor eXist-db
  • Cargar de forma sencilla un contenido JSON en Android con Volley mediante un JSONArray
697975388 677161711 610584111 674252978 667330098 658127182 637165264 675770163 633169707 620547759 682763476 606166639 687693401 649714576 693045788 694055891 660415499 636240127 658043186 641911693 664888275 600041009 669411367 676354752 680685899 621874358 629781076 690789015 627582077 692045853 698207351 603372817 633242993 612490354 618435155 651825479 627381621 664674497 694784525 697824449 649386419 630944247 674994099 621196399 669678992 613531183 639829657 606271623 603554110 620672424 673414210 681806816 612157736 635854817 690300812 686889019 635542862 639904786 621823155 629941745 612577926 630703175 683848961 679566650 623302482 653040587 641230748 621543397 685459215 669158871