You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "Saha, Sanjeev" <SS...@asce.org> on 2004/08/03 18:40:29 UTC
Retaining XmlCursor on a newly ceated/added XmlObject
Sure, please consider the following:
Xml Fragment
=============
<ResultSet>
<Row>
<Column1/>
<Column2/>
</Row>
<Row>so on and so forth
</Row>
</ResultSet>
pseudo code
============
apiToHandleResultSet()
{
for (every row in result set)
{
newXObj = XmlObject.Factory.newInstance();
XmlCursor cursor = newXObj.newCursor();
apiToHandleEachRow(newXObj, cursor);
add newXObj to the ResultSetXObj;
apiToHandleAdvancedRowProcessing(ResultSetObj, cursor);
}
}
Of course, as was previously noted, 'cursor' is now pointing to the newXObj which was left behind and not to the XmlObject that was added to the ResultSet. I changed the approach for the newXObj to be added to the ResultSet after completing the advanced operations. However, it wasn't as clean as I would have wanted to have. Still, it works fine :o)
As the <Row> is not associated with any namespace and there is not definitive way to use an xpath without knowing any specific value in the element{I could, logically speaking, add the <Row> as the last element in the document and then have the advanced api to retrieve it, but didn't want to tie it to any specific location dependent retrieval logic} I was wondering whether there was any option to keep the cursor pointing to the newly added <Row>.
I completely agree with the design behind retaining the cursor with the document that was created before adding it to the ResultSet, but I was curious to try it out since the documentation for XmlCursor.copyXml(XmlCursor toHere) mentions that "The cursors and bookmarks located in the XML that was copied are also copied to the new location".
Maybe I am missing something ;-) Thanks in advance for any clarifications.
Regards,
Sanjeev
Date: Tue, 27 Jul 2004 09:48:07 -0700
From: Eric Vasilik <er...@bea.com>
When you move the row, the cursor stays behind, in the document which
contained the row. This is by design. If you have the XmlObject of the
row, you can acquire a new cursor on it by calling XmlObject.newCursor.
Will this work for you? Could you provide a more concise example?
-----Original Message-----
From: Saha, Sanjeev [mailto:SSaha@asce.org]
Sent: Tuesday, July 27, 2004 8:13 AM
To: xmlbeans-user@xml.apache.org
Subject: Retaining XmlCursor on a newly ceated/added XmlObject
For the sample xml:
<ResultSet>
<Row>
<Column1/>
<Column2/>
</Row>
<Row>so on and so forth
</Row>
</ResultSet>
The <Row> is processed by a separate api and returned as an XmlObject.
After the <Row> is returned, it is added to the <ResultSet> for further
processing. Since the <Rows> have the same 'Name' it becomes difficult
to process the most recently returned <Row>.
Is there a way to retain the XmlCursor of the <Row/> that is returned so
that after it is added to the <ResultSet> processing on the same can be
continued?
The api that deals with the <ResultSet> creates the <Row> XmlObject and
passes it on for processing. Which is to say that it knows what object
was worked upon including the XmlCursor on the <Row>, however, I lose
this reference as soon as I add it to the <ResultSet> object :o(
I've tried fromCursor.copyXml(toCursor), but it still points to the
independently created <Row> object and not the <Row> embedded in the
<ResultSet>.
Thanks in advance,
Sanjeev
- ---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/