Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Claude Carter   on Jul 28 In Java Category.

  
Question Answered By: Daisy Phillips   on Jul 28

I am new to exist  and i find some code for importing exist servlet and i have sme code for
retrieving xml  from DB,


import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
public class Example1 {
public static void main(String[] args) throws Exception {
Collection col = null;
try {
String driver = "org.dbxml.client.xmldb.DatabaseImpl";
Class c = Class.forName(driver);

Database database = (Database) c.newInstance();
DatabaseManager.registerDatabase(database);
col =
DatabaseManager.getCollection("xmldb:dbxml:///db/addresses");

String xpath = "/address[@id = 1]";
XPathQueryService service =
(XPathQueryService) col.getService("XPathQueryService", "1.0");
ResourceSet resultSet = service.query(xpath);
ResourceIterator results = resultSet.getIterator();

while (results.hasMoreResources()) {
Resource res = results.nextResource();
System.out.println((String) res.getContent());
}
}
catch (XMLDBException e) {
System.err.println("XML:DB Exception occurred " + e.errorCode + " " +
e.getMessage());
}
finally {
if (col != null) {
col.close();
}}}}
but i want to know how can i update  my xml doc? for updating my doc i must execute some query like this:
for $address in //address
return
(: Move lname and fname into a new name element :)
update replace $address with
<address>
<name>
<family>{$address/lname/text()}</family>
<given>{$address/fname/text()}</given>
</name>
{$address/city, $address/email}
</address>
or this:
<xupdate:modifications version="1.0"
xmlns:xupdate="http://www.xmldb.org/xupdate">
<xupdate:update select="/address[@id = 1]/name/last">Herman</xupdate:update>
</xupdate:modifications>

what is the difference beween two types? how can i do this work?

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on eXist Or get search suggestion and latest updates.


Tagged: