Typical, I bang my head all afternoon, post, then it
finally dawns on me - I now have it sort of working.

However, could someone in the know tell me if this
is the "correct" approach ?  I'm especially not
sure about the "node(0)"  line.


 public void setValueAt(Object o, int row, int col) { 

  Object object = definition.getRowXPath().selectNodes(source).get(row);
  
  Iterator i =
((org.dom4j.tree.DefaultElement)object).elementIterator();

  for ( Iterator iter = i; iter.hasNext(); ) 
  {
    Object oo = iter.next();

    org.dom4j.Node  n = ((org.dom4j.tree.DefaultElement)oo).node(0);

    System.err.println(n);
    n.setText(o.toString());
   }

}


John Sharp wrote:
> 
> Hi,
> I'm following from an earlier suggestion to make  XMLTableModel
> updates.  The method was to use XPath to map back from the table
> row/col to the Node at this location in the document.
> 
> The following code does update the document (via the node handle)
> but at the wrong place - always at the second last row.
> 
> public void setValueAt(Object o, int row, int col) {
> 
>   Object object = definition.getRowXPath().selectNodes(source);
> 
>   if ( object instanceof List ) {
>     List list = (List) object;
>     for ( Iterator iter = list.iterator(); iter.hasNext(); ) {
>        Object obj =  iter.next();
> 
>        org.dom4j.tree.DefaultElement defaultElement =
>          (org.dom4j.tree.DefaultElement) obj;
> 
>                  System.err.println( "rowIndex:" + row );
>                  System.err.println( "nodeCount:" + defaultElement.nodeCount()  );
>                  System.err.println( "name:" + ((org.dom4j.Node)
> defaultElement.node(row)).getName() );
>                  System.err.println( "parent:" + defaultElement.getParent());
> 
>                  org.dom4j.Node node = defaultElement.node(row);
> 
>                  if (defaultElement.nodeCount() ==1) {
>                    node.setText("****NEW*VALUE****");
>                    return;
>                  }
>              }
>          }
> 
> The xml data file is follows:-
> <?xml version="1.0"?>
> 
> <EngineeringSpecification
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>       xsi:noNamespaceSchemaLocation="spec.xsd">
> 
> <Summary>
>  <device>F711111</device>
> </Summary>
> <Summary>
>  <device>F722222</device>
> </Summary>
> <Summary>
>  <device>F733333</device>
> </Summary>
> <Summary>
>  <device>F744444</device>
> </Summary>
> <Summary>
>  <device>F755555</device>
> </Summary>
> 
> </EngineeringSpecification>
> 
> --
> John.
> 
> -------------------------------------------------------
> This sf.net email is sponsored by: To learn the basics of securing
> your web site with SSL, click here to get a FREE TRIAL of a Thawte
> Server Certificate: http://www.gothawte.com/rd524.html
> _______________________________________________
> dom4j-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/dom4j-user

-- 
 Texas Instruments Inc  Product Development    tel:214 480 4253
 PO BOX 660199          MS: 8645 FORE/A-3101   fax:214 480 4401
 12500 TI Boulevard     Dallas, TX 75266-0199       
     nawk nawk,  Who's there ?   Aho, Weinberger and Kerninghan.


-------------------------------------------------------
This sf.net email is sponsored by: To learn the basics of securing 
your web site with SSL, click here to get a FREE TRIAL of a Thawte 
Server Certificate: http://www.gothawte.com/rd524.html
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to