Hi Trevor!
Thanks for the hint. I now have added complexity to my application in the update part (of course I don’t mind :-).
As you suggested, I query just enough of the input-query to successfully update the document afterwards (baseQuery).
Then I want to walk to the most inner node via XPATH, but unfortunately get an Error (which comes from XPATH and JDOM Version 0.9beta, which is available since shortly). I will describe the error after the code-snippet:
>>>>>>>>>>>>>>>>
public boolean update(TQuery query,String updatedText,String encoding) throws TException {
try {
// Invoke the query to obtain the document and to lock it
try {
TResponse testresponse = accessor.query(query);
} catch (Exception e) { return false; }
int startchar = 1;
String baseQuery = "";
String restQuery = "";
char qchar;
do {
qchar = query.toString().charAt(startchar);
if(qchar!='/') {
startchar++;
}
} while(qchar!='/');
try {
baseQuery = query.toString().substring(0,startchar);
restQuery = query.toString().substring(startchar+1,query.toString().length());
} catch (Exception e) {}
System.out.println("\n\nBase:"+baseQuery+"\nRest:"+restQuery+"\nWhole:"+query.toString());
TResponse response = accessor.query(TQuery.newInstance(baseQuery));
// Obtain the TXMLObject from the response
TXMLObject xmlObject = response.getFirstXMLObject();
if ( xmlObject == null )
return false;
// Obtain the JDOM element and update its content
xmlObject.setEncoding(encoding);
Element element = (Element)xmlObject.getElement();
if(restQuery.equals("")) {
element.setText(updatedText);
} else {
Element child = null;
Object ilxp;
try {
[B]XPath xpath = XPath.newInstance(restQuery);[/B]
ListIterator lxp = xpath.selectNodes(xpath).listIterator();
while(lxp.hasNext()) {
ilxp = lxp.next();
child = element.getChild((String)ilxp);
}
System.out.println("\n\nXPath:"+xpath.getXPath()+"\nChild"+child.toString());
child.setText(updatedText);
} catch (Exception e) {}
}
// Invoke the update
xmlObject.writeTo(System.out);
response = accessor.update(xmlObject);
return true;
}
// TQueryException and TUpdateException are both derived from TAccessorException
// so we simply use the base class here
catch (TAccessorException accessorException) {
showAccessFailure( accessorException );
throw accessorException;
}
}
</pre><BR><<<<<<<<<<<<<<<<<BR><BR>The XML:<BR><BR><pre class="ip-ubbcode-code-pre">
<patient>
<name>
<surname>xxx</surname>
<firstname>yyy</firstname>
</name>
....
</patient>
The baseQuery, which can be updated is:
/patient[@ino:id=1]
The rest, which I want to walk via XPath: name/surname (if I type in element.getChild(“name”).getChild(“surname”); it works)
Whole:/patient[@ino:id=1]/name/surname
The error I get:
java.lang.NoClassDefFoundError: org/saxpath/SAXPathException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at org.jdom.xpath.XPath.newInstance(XPath.java:133)
at TaminoInterface.update(TaminoInterface.java:139)
at TaminoInterface.update(TaminoInterface.java:165)
at TaminoCom.bUpdateActionPerformed(TaminoCom.java:446)
at TaminoCom.access$300(TaminoCom.java:26)
at TaminoCom$4.actionPerformed(TaminoCom.java:186)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5093)
at java.awt.Component.processEvent(Component.java:4890)
at java.awt.Container.processEvent(Container.java:1566)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Container.dispatchEventImpl(Container.java:1623)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
at java.awt.Container.dispatchEventImpl(Container.java:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1585)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
After the easter-weekend I will check out the error,
bye and have a nice weekend,
Rob
#webMethods-Tamino-XML-Server-APIs#webMethods#API-Management