Hi Patrizio, execQuery() methods return new documents (there are queries that construct new documents), so the modifications on results will not affect the original. In your case, you should be better off using XMLCursor.selectPath(). This method will set a selection on the original document, than use hasNext/toNextSelection methods to navigate.
Avoid creation of many cursors, if you want to improve performance, in your case one is probably enough, moving a cursor anywhere in a document is much faster than managing many cursors. After you're done with it don't forget to call dispose(). Cezar > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Sent: Friday, April 06, 2007 10:41 AM > To: user@xmlbeans.apache.org > Subject: XMLBeans and XmlCursor > > > Hi all, > > I've just started to use XMLBeans and I had some troubles to use > XmlCursor to navigate through a document, update it and get back the > updated version. > > This is my xml document: > > <?xml version="1.0" encoding="UTF-8"?> > <eda:quoteEvent xmlns:eda="http://www.bsource.ch/EDA"> > <eda:security>CS GROUP N</eda:security> > <eda:date>09-03-2007</eda:date> > <eda:time/> > <eda:national-nr>1213853</eda:national-nr> > <eda:change>-0.2</eda:change> > <eda:volume>5821192</eda:volume> > <eda:currency transcoder="CURRENCY">CHF</eda:currency> > <eda:prev-close>87.9</eda:prev-close> > <eda:open>87.75</eda:open> > <eda:last>87.7</eda:last> > </eda:quoteEvent> > > I would like to retrieve all nodes with transcoder attribute (I've used > the //@transcoder/.. expression), call another component (for > transcodification) and get back the below new one: > > <?xml version="1.0" encoding="UTF-8"?> > <eda:quoteEvent xmlns:eda="http://www.bsource.ch/EDA"> > <eda:security>CS GROUP N</eda:security> > <eda:date>09-03-2007</eda:date> > <eda:time/> > <eda:national-nr>1213853</eda:national-nr> > <eda:change>-0.2</eda:change> > <eda:volume>5821192</eda:volume> > <eda:currency transcoder="CURRENCY">001</eda:currency> > <eda:prev-close>87.9</eda:prev-close> > <eda:open>87.75</eda:open> > <eda:last>87.7</eda:last> > </eda:quoteEvent> > > The code is: > > XmlObject xobj = XmlObject.Factory.parse(new > ByteArrayInputStream(bodyEvent.getBytes())); > XmlObject response = EDATool.transcodification (xobj, "SMI-EDA"); > > where > > public static XmlObject transcodification (XmlObject bodyEvent, String > encoder) throws Exception > { > if ((bodyEvent == null) || (encoder == null)) > throw new Exception("unexpected null object"); > > long start = System.currentTimeMillis(); > XmlObject[] elems = bodyEvent.execQuery("//@transcoder/.."); > System.out.println ("execQuery elapsed time msec: " + > (System.currentTimeMillis() - start)); > > for (int i = 0; i < elems.length; i++) > { > XmlCursor cursor = elems[i].newCursor(); > TokenType token = null; > > String value = cursor.getTextValue(); > String table = null; > > while (cursor.hasNextToken()) > { > token = cursor.toNextToken(); > if (token.isAttr() && > "transcoder".equals(cursor.getName().toString())) > { > table = cursor.getTextValue(); > break; > } > } > > if (table != null) > { > cursor.pop(); > value = transcode(table, encoder, value); > cursor.setTextValue(value); > } > cursor.dispose(); > } > return bodyEvent; > } > > My doubts: > > 1) I noticed that the time for executing execQuery is not neglectable > (msec: 3688 for a document of only 471 bytes). > What is wrong in my code ? > 2) after disposing the cursor the document is not updated, how could I > write back my changes to the document ? > > Regards > Patrizio > Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]