OK I figured it out. It was my lack of understanding of how cursor.getObject() works. There must be some good reason behind this design but it sure is tricky.
xmlObj = cursor.getObject() returns the typed contents of the current start/startdoc cursor position and it excludes the container element itself and so it does not show up in xmlObj.xmlText(). But it does store the QName of the parent element somewhere as it can be accessed again by calling xmlObj.newCursor.getName(). It would be good though if this could be accessible without creating the new cursor. Now I am wondering what would be the way to create the container XMLObject from this one, so the xmlText shows the container element name as well. Tried two things without success: 1) XMLObject.Factory.parse(xmlObj.newXMLStreamReader()). The xmlText() remains the same, perhaps the new one might have lost the information about the cursor name that represented the container element. 2) newObj = XMLObject.Factory.newInstance() newObj.set(xmlObj); This one threw exception: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException I would appreciate any help or ideas. regards kapil Kapil Anand wrote: > > Thanks for replying Jacob. > I tried cursor.child(1) but it returns false. (child index 1 anyway > represents the second child of the current cursor position and i need to > select the first child). This is what i am inferring from the behavior of > the api: > > When i start with the XmlObject that represents the untyped document, the > first child under it is an xml-fragment containing the contents of the > root element. But this does not make sense. It might make perfect sense > perhaps if I had started with a schema and declared things like this: > > <xs:complexType name="ElemT"> > ... > </xs:complexType> > <xs:element name="RootElem" type="ElemT"/> > > But I have doubts about this even for typed XmlObject, because it might be > right if i am trying to get to the next token, but next child should > always be a concrete node as per my understanding. > > This assumption/inference is proved wrong when i try to move to the first > child of this xml-fragment, it actually takes me to the subsequent child, > so child navigation is correct the contents of the intermediate child are > incorrect. > > I will try to explain in problem with the tree. > RootElement > -> Level1.1 > -> Level2-1.1 > -> Level1.2 > -> Level2-1.2 > -> Level1.3 > -> Level2-1.3 > First cursor.toChild(0) should return Level1.1 but instead it returns all > the children of Root inside an xml-fragment. Dont know if this is expected > behavior but it does not match the behavior of the next call to > cursor.toChild(0) since it correctly returns Level2-1.1. So although the > first time the cursor was pointing to Level1.1, it somehow returned wrong > XML fragment in cursor.getObject(); > > When i use an XML with single child for each parent it works fine (no > siblings at any level). It returns Level1.1 in the first call and > Level2-1.1 in the next call, so on and so forth. > > regards > kapil > -- View this message in context: http://www.nabble.com/Navigating-Untyped-XmlObject-with-XmlCursor-tp22463857p22469181.html Sent from the Xml Beans - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

