Page 1 of 1

CustomXmlDataStorage-setTextContent(String) undefined

PostPosted: Tue Jul 21, 2009 9:59 pm
by Leigh
Hi,

I updated my sources and noticed Eclipse is reporting an error in CustomXmlDataStorage.java. Any ideas why eclipse/jdk 1.6.0_13 is reporting:

The method setTextContent(String) is undefined for the type Node

?
The interface and method certainly seem to exist in the rt.jar.

Code: Select all
   public boolean setNodeValueAtXPath(String xpath, String value, String prefixMappings) throws Docx4JException {

      try {
         getNamespaceContext().registerPrefixMappings(prefixMappings);

         Node n = (Node)xPath.evaluate(xpath, doc, XPathConstants.NODE );
         if (n==null) {
            log.debug("xpath returned null");
            return false;
         }
                        // *** Error reported on this line ****
         n.setTextContent(value);
         
         // cache is now invalid
         return true;
      } catch (Exception e) {
         throw new Docx4JException("Problem setting value at xpath " + xpath);
      }
      
   }


-Leigh

Re: CustomXmlDataStorage-setTextContent(String) undefined

PostPosted: Mon Aug 03, 2009 4:04 pm
by jason
It works for me when the node is com.sun.org.apache.xerces.internal.dom.ElementNSImpl,
but not when crimson is being used (org.apache.crimson.tree.ElementNode2).

So, there are 2 ways to fix this:

First, put

Code: Select all
System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
         "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");


in the static initialiser in CustomXmlDataStorageImpl.

Or alternatively, use createTextNode instead of setTextContent

Commit r863 does the latter.