xml-xindice-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yan Langlois <yan.langl...@eseo.fr>
Subject Re: Change a DOM value and save to database
Date Sat, 14 May 2005 20:58:25 GMT
Hi,

In my last project with Xindice I had to insert/remove/update nodes 
directly on the database. I used XUpdate to do it. Here I think you 
should generate an XUpdate query to save the modifications. See 
http://xml.apache.org/xindice/1.0/guide-developer.html#Using+XUpdate+to+Modify+the+Database

for more information.

Yan.

Tadej Lasic wrote:

> Hi,
>
> I have a question about Xindice and DOM node value manipulation. My 
> program
> needs to read an XML document from the database, read the elements and 
> text
> values and allow the user to change text values and then save the XML
> document with the changed values back into the database while maintaining
> the structure. I'm using Xindice 1.0 and J2SE 1.4.2.
>
> Now, I can open and read a DOM document with Xindice using the
> getContentAsDOM() method and traverse it with NodeIterator, but I 
> don't know
> how I could manipulate a certain Node.TEXT value and than store the whole
> XML document into the database without changing the structure or any 
> of the other values. Here's some code:
>
> public class Xindice {
>    static Node node;
>
>    public static void main(String[] args) throws Exception {
>        Collection col = null;
>
>        try {
>            String driver = 
> "org.apache.xindice.client.xmldb.DatabaseImpl";
>            Class c = Class.forName(driver);
>
>            Database database = (Database) c.newInstance();
>            DatabaseManager.registerDatabase(database);
>            col =
>                    DatabaseManager.getCollection(
>                            "xmldb:xindice:///db/addressbook");
>
>            XMLResource document = (XMLResource) 
> col.getResource("address");
>
>            if (document != null) {
>                // Create the NodeIterator
>
>                DocumentTraversal traversable = (DocumentTraversal)
> document.
>                                                getContentAsDOM();
>                NodeIterator iterator = traversable.createNodeIterator(
>                        document.getContentAsDOM(), NodeFilter.SHOW_ALL,
> null, true);
>
>                while ((node = iterator.nextNode()) != null) {
>
>                    switch (node.getNodeType()) {
>
>                    case Node.TEXT_NODE:
>                        if (!node.getNodeValue().trim().equals("")) {
>
>                            node.setNodeValue("test");
>                            
> System.out.println(node.getNodeValue().trim());
>
>                        }
>                        break;
>
>                    }
>
>                } //while
>
>            } else {
>                System.out.println("Document not found");
>            }
>        } catch (XMLDBException e) {
>            System.err.println("XML:DB Exception occured " + e.errorCode);
>        } finally {
>            if (col != null) {
>                col.close();
>            }
>        }
>    }
>
> }
>
> As you can I try to set a new value using node.setNodeValue("test") but I
> don't know how to get the changed DOM tree into the database. Any help 
> would
> be very appreciating.
>
> Regards,
>        Tadej
>
>


Mime
View raw message