Update problem - TXMLObject.setId() does not work

I try to do the following:

1. Load a XML Document from the database.
2. Close Connection.
3. Do something with the DOM Document (update contents)
4. Open new Connection and everything needed to perform an update operation
5. …
TXMLObject xmlObj = TXMLObject.newInstance
(DOMDoc.getDocumentElement());
// There is no id in the xmlObj ! Why ?

xmlObj.setId(DOMDoc.getDocumentElement().getAttribute(“ino:id”));
// There is still no ino:id in the xmlObj

String knownInoId = “2”; // example
xmlObj.setId(knownInoId);
// still no ino:id

xmlObj.update();
// update fails (no id, no docname)


Why does a call to xmlObj.setId() not work ?
I need the id to update the document, docname is not sufficient.

Any help is very much appreciated !

Sorry, I could not update my former message, so here is some more information:

I try to do the following:

String database = “nameOfDB”;
String user = “userId”;
String passwd = “verySecret”;
String coll = “nameOfCollection”;

TConnection c = TConnectionFactory.getInstance().newConnection(database, user, passwd);
TAccessLocation accessLoc = TAccessLocation.newInstance(coll);
TXMLObjectAccessor objAcc = c.newXMLObjectAccessor(accessLoc,TDOMObjectModel.getInstance());

TQuery q = TQuery.newInstance(“aSpecificQuery”);
TResponse r = objAcc.query(q);
TXMLObjectIterator it = r.getXMLObjetcIterator();

TXMLObject o = it.next();
Element elem = (Element)o.getElement();

c.close(); // close Connection


// do sth with the DOM elem
elem.setAttribute(“newAttribute”,“newAttributeValue”);


c = TConnectionFactory.getInstance().newConnection(database, user, passwd);
accessLoc = TAccessLocation.newInstance(coll);
objAcc = c.newXMLObjectAccessor(accessLoc,TDOMObjectModel.getInstance());

// to perform the update, instantiate a
// TXMLObject from the DOM-Element
o = TXMLObject.newInstance(elem);


objAcc.update(xmlObj);
c.close();



Problem:

The TXMLObject has no ino:id after the call to
newInstance(elem), though there is an ino:id attribute in the elem.
If I try o.setId(knownInoId), there is still no in:id in the TXMLObject.
The effect is, that the call to update() does not work as intended.

The attributes docname, doctype and collection are not set also.

Where ist the id (other attributes) after the call to newInstance(elem)?
Why does a call to xmlObj.setId() not work ?
I need the id to update the document, docname is not sufficient.

Any help is very much appreciated !

I can’t reproduce your problem but I’m not sure why you need to create a new TXMLObject anyway. Why not just update the one you already have?

TConnection c = TConnectionFactory.getInstance().newConnection(database, user, passwd);
TAccessLocation accessLoc = TAccessLocation.newInstance(coll);
TXMLObjectAccessor objAcc = c.newXMLObjectAccessor(accessLoc,TDOMObjectModel.getInstance());

TQuery q = TQuery.newInstance("query");
TResponse r = objAcc.query(q);
TXMLObjectIterator it = r.getXMLObjectIterator();
TXMLObject o = it.next();
Element elem = (Element)o.getElement();

// do sth with the DOM elem
elem.setAttribute("attribute","value");

objAcc.update(o);
c.close();


Does this help, or have I missed something?

Thanks for the help.

I need a new TXMLObject because I use a servlet which gives me a XML Document as the response and later I call another servlet to do the update. So I lose the first (original) TXMLObject.

I got it to work somehow yesterday, after much debugging.

I don’t exactly know why, but now it’s working.
I won’t touch this part of the code again :wink:

Thanks again.