hi
 
we can add the document through java
in xindice example we have the java file "addDocument.jaa"
we have to change the URI, then we can add the document
 
here is the code
 

package com.celestials.dao.db.services;

/*

* Created on Dec 6, 2004

*

* TODO To change the template for this generated file go to

* Window - Preferences - Java - Code Generation - Code and Comments

*/

import java.io.File;

import java.io.FileInputStream;

import org.xmldb.api.base.Collection;

import org.xmldb.api.base.XMLDBException;

import org.xmldb.api.modules.XMLResource;

/**

* @author Hanif

*

* TODO To change the template for this generated type comment go to

* Window - Preferences - Java - Code Generation - Code and Comments

*/

/**

* Simple XML:DB API Example to insert a new document into the database.

*/

public class AddDocument extends AbstractExample {

public static void main(String[] args) throws Exception {

Collection collection = null;

try {

collection = getCollection("xmldb:xindice://localhost:8080/db/efiler");

String args0 = null;

System.out.println(args.length);

if(args.length==0) {

args0 = "c:/Project.xml";

} else {

args0 = args[0];

}

String data = "">

XMLResource document = (XMLResource) collection.createResource(null, "XMLResource");

document.setContent(data);

// document.setContentAsSAX();

collection.storeResource(document);

System.out.println("Document " + args0 + " inserted as " + document.getId());

}

catch (XMLDBException e) {

System.err.println("XML:DB Exception occured " + e.errorCode + " " + e.getMessage());

}

finally {

if (collection != null) {

collection.close();

}

}

}

public static String readFileFromDisk(String fileName) throws Exception {

File file = new File(fileName);

System.err.println(file.exists());

FileInputStream insr = new FileInputStream(file);

byte[] fileBuffer = new byte[(int) file.length()];

insr.read(fileBuffer);

insr.close();

return new String(fileBuffer);

}

}

urs
hanif

"R. Mark Volkmann" <[EMAIL PROTECTED]> wrote:
Quoting 肖 鹏程 <[EMAIL PROTECTED]>:

> If you use xindice 1.0, you'd try it with xindice 1.1!

I'm using 1.1b4 and it doesn't work. Has anyone else been able to add documents
to a collection from Java? If so, can you send me an example?

> >From: "R. Mark Volkmann" <[EMAIL PROTECTED]>
> >Reply-To: xindice-users@xml.apache.org
> >To: xindice-users@xml.apache.org
> >Subject: XUpdate to add a document to a collection
> >Date: Tue, 4 Jan 2005 10:47:11 -0600
> >
> >I need to add a document to a collection from a Java application. I'm
> trying to
> >do this using the XUpdate API. Is this the best way?
> >
> >Here is the xupdate string I'm passing to my XUpdateQueryService update
> method.
> >
> >
> >
> >
> > foo
> > bar
> >

> >

> >

> >
> >It fails with the following stack trace.
> >
> >org.xmldb.api.base.XMLDBException: org.apache.xmlrpc.XmlRpcException:
> Error
> >Compiling XPath _expression_: null
> > at
>
>org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl.runRemoteCommand(CollectionImpl.java:119)
>
> > at
>
>org.apache.xindice.client.xmldb.xmlrpc.CollectionImpl.query(CollectionImpl.java:515)
>
> > at
>
>org.apache.xindice.client.xmldb.XindiceCollection.query(XindiceCollection.java:259)
>
> > at
>
>org.apache.xindice.client.xmldb.services.QueryService.query(QueryService.java:90)
>
> > at
>
>org.apache.xindice.client.xmldb.services.XUpdateQueryServiceImpl.update(XUpdateQueryServiceImpl.java:81)
>
> >
> >Any suggestions would be greatly appreciated!
> >
> >--
> >R. Mark Volkmann
> >Partner, Object Computing, Inc.
>
> _________________________________________________________________
> 享用世界上最大的电子邮件系统— MSN Hotmail。 http://www.hotmail.com
>
>


--
R. Mark Volkmann
Partner, Object Computing, Inc


Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.

Reply via email to