xml-xindice-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tadej Lasic" <t...@siol.com>
Subject Change a DOM value and save to database
Date Sat, 14 May 2005 16:20:19 GMT

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();
            col =

            XMLResource document = (XMLResource) col.getResource("address");

            if (document != null) {
                // Create the NodeIterator

                DocumentTraversal traversable = (DocumentTraversal)
                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("")) {




                } //while

            } else {
                System.out.println("Document not found");
        } catch (XMLDBException e) {
            System.err.println("XML:DB Exception occured " + e.errorCode);
        } finally {
            if (col != null) {


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.


No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.10 - Release Date: 13.5.2005

View raw message