Fyi, just to follow this up - I replaced my JDOM code with some new code that uses DOM and also doesn't work.

If someone has some sample code that can set values using context.setValue() in an XML Document which is stored as a String inside a bean, I'd love to see it.

phil.

Dmitri Plotnikov wrote:

Phil,

There might be some kind of version incompatibility in your
environment.  JXPath is built against JDOM b9.  It should also work
without any rebuilding with JDOM b10.

Make sure you have 1) JDOMb9 or b10: http://www.jdom.org/dist/binary/
2) the latest JXPath:
http://archive.apache.org/dist/jakarta/commons/jxpath/jxpath_1.2RC1/


Let me know if upgrading to the latest versions addresses your problem.


- Dmitri

--- WHIRLYCOTT <[EMAIL PROTECTED]> wrote:

I'm using JXPath for some read only work right now and it's quite helpful. However, now that I'm trying to do some writes to a simple bean with a JDOM Document inside it, things are starting to get trickier. I'm using a JXPath nighly build from a few days ago.

I've attached a short sample of what I'm trying to do in the hope
that someone can take a look at it and guide me.


In essence, I'm having trouble using the context.setValue() method
and I'm getting exceptions like this:


org.apache.commons.jxpath.JXPathException: Exception trying to set
value with xpath /dataXML/address/street; org.jdom.Element.addContent(Lorg/jdom/Text;)Lorg/jdom/Element;
at



org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.setValue(JXPathContextReferenceImpl.java:421)

at


org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.setValue(JXPathContextReferenceImpl.java:412)

        at com.whirlycott.samples.JXPathTest.main(JXPathTest.java:35)
Exception in thread "main"

Thanks in advance,
phil.

--
                                  Whirlycott
                                  Philip Jacob
                                  [EMAIL PROTECTED]
                                  http://www.whirlycott.com/phil/

/*

* Created on Jul 11, 2004 by pjacob * */ package com.whirlycott.samples;

import java.io.StringReader;

import org.apache.commons.jxpath.JXPathContext;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;

/**
* @author pjacob
*
*/
public class JXPathTest {
        
        private String data = "<?xml version=\"1.0\"
?><address><street>Orchard Road</street></address>";
        private String firstName;
        
        public static void main(String[] args) {
                JXPathTest test = new JXPathTest();
                
                JXPathContext context = JXPathContext.newContext( test );
                
                //This works fine.
                debug(context.getValue("/dataXML/address/street"));
                
                //This doesn't.  Why not?
                Element address = new Element("address");
                address.setText("123 Happy Street");

                context.setValue("/dataXML/address/street", address);
                
                //Print the value to see if it's changed.
                debug(context.getValue("/dataXML/address/street"));
        }
        
        /**
         * @param value
         */
        private static void debug(Object value) {
                System.out.println(value);
        }

        /**
         * Convert a String (of XML) into a Document
         * @param _xml
         * @return
         */
        public Document buildDocumentFromString(String _xml) {
                SAXBuilder builder = new SAXBuilder();
                Document doc = null;
                try {
                        doc = builder.build(new StringReader(_xml));
                } catch (Exception e) {
                        debug(e.getMessage());
                        e.printStackTrace();
                }
                return doc;
        }
        
        /*
         * Bean methods
         */
        
        public Document getDataXML() {
                return buildDocumentFromString( getData() );
        }

        private String getData() {
                return data;
        }
        
        public String getFirstName() {
                return firstName;
        }
        
        public void setFirstName(String firstName) {
                this.firstName = firstName;
        }
}



---------------------------------------------------------------------

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


-- Whirlycott Philip Jacob [EMAIL PROTECTED] http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to