You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xmlbeans.apache.org by Wolfgang Hoschek <wh...@lbl.gov> on 2004/02/13 00:45:24 UTC

RE: get/set methods for element

Hi, just my 5 cents on the issue at hand.

Although xsd:any with maxOccurs can be manipulated with XMLCursor this 
seems an unnecessary complication to me.
IMHO, xmlbeans should ALSO spit out the highly convenient array accessor 
methods it usually spits out when using concrete elements instead of 
xsd:any, as follows:

getAnyArray()
getAnyArray(int)
insertAny(int, XMLObject)
removeAny(int)
setAnyArray(XMLObject[])
setAnyArray(int, XMLObject)
sizeOfAnyArray()

This would mean that things like the example below (which i use in a 
great many actual schemas) can be manipulated "as expected" and with a 
minimal learning curve.

<xsd:complexType name="ItemSetType">
	<xsd:sequence>
		<xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded">
	</xsd:sequence>
</xsd:complexType>

Am I missing out on something here?

Wolfgang.

> If you want to insert an existing XmlObject, then you would first
> position a cursor at the desired destination position (as I showed
> before), then you would create another XmlCursor from the source
> XmlObject and then call moveXml or copyXml on the source cursor, passing
> as an argument, the target cursor.
> 
> If, however, you do not have a source XmlObject, but just want to
> construct some XML at a given position, say
> <anything1><anything2/></anything1>, you could position a cursor to
> where you want to insert the new XML and:
> 
>     cursor.beginElement( "anything1" );
>     cursor.insertElement( "anything2" );
> 
> Hope this helps,
> Eric
>     
> 
> -----Original Message-----
> From: Ganga Sah [mailto:ganga_sah@yahoo.com] 
> Sent: Monday, January 05, 2004 11:05 PM
> To: xmlbeans-dev@xml.apache.org
> Subject: RE: get/set methods for <xsd:any> element
> 
> Hi Eric,
> Thanks for your reply.
> I want to start with XML instance
> "<foo><bar>xyx</bar></foo>", and insert an
> XmlObject(say, "<anything1><anything2/></anything1>"
> corresponding to xsd:any element) as the first child
> of FooType object to get say,
> "<foo><anything1><anything2/></anything1><bar>xyx</bar></foo>".
> I am unable to do this using XmlCursor API, as
> XmlCursor.insertElement()/beginElement() methods does
> not take XmlObject as parameter but take only simple
> element(string)??
> How can I insert XmlObject into an existing XML
> content tree?
> thanks,
> ganga
> 
> --- Eric Vasilik <er...@bea.com> wrote:
>> Given an XmlObject (all user generated objects
>> derive from this), you
>> can call newCursor().  This will return an XmlCursor
>> which is positioned
>> at the element or attribute associated with the
>> XmlObject.
>> 
>> Thus, in your case, from FooType, you could:
>> 
>>     FooType ft = ....;
>>     XmlCursor c = ft.newCursor(); // Cursor is at
>> <foo>
>>     c.toFirstChild();             // Cursor is at
>> <a:bbbb>
>>     c.toNextSibling();            // Cursor it at
>> <bar>
>>     etc ...
>> 
>> You can transition back to XmlObject from an
>> XmlCursor by calling
>> getObject() on the cursor.  If this object has a
>> java type, you will be
>> able to cast it appropriately.  
>> 
>> Does this help?
>> 
>> - Eric
>> 
>> -----Original Message-----
>> From: Ganga Sah [mailto:ganga_sah@yahoo.com] 
>> Sent: Monday, January 05, 2004 12:01 PM
>> To: xmlbeans-dev@xml.apache.org
>> Subject: RE: get/set methods for <xsd:any> element
>> 
>> Hi Eric,
>> My schema has following pattern:
>> <schema ..>
>> <element name="foo" type="FooType"/>
>> 
>> <xsd:complexType name="extType">
>>  <xsd:sequence>
>>   <xsd:any minOccurs="0" maxOccurs="unbounded"
>> namespace="##other"/>           
>>  </xsd:sequence>
>> </xsd:complexType>
>> 
>> <xsd:complexType name="FooType">
>>  <xsd:complexContent>
>>   <xsd:extension base="extType">         
>>    <xsd:sequence>
>>     <xsd:element name="bar" type="xsd:string" />
>>    </xsd:sequence>
>>    </xsd:extension>
>>   </xsd:complexContent>                	
>> </xsd:complexType>
>> </schema>
>> 
>> Correspong xml-fragment is:
>> 
>> <foo>
>>   <a:bbbb xmlns:a="aaaa">
>>   <bar>some-content</bar>
>> </foo>
>> 
>> I have got content of this XML instance in FooType
>> Java object.
>> How can I use xmlCursor to get(or set) the
>> un-named(xsd:any) element(first child of FooType
>> here)?
>> Could you help me by giving me a code snippet to do
>> this?
>> 
>> thanks a lot,
>> ganga
>> 
>> 
>> 
>> 
>> --- Eric Vasilik <er...@bea.com> wrote:
>> > We do not generate methods for the any elements. 
>> > However, you can use XmlCursor to navigate this
>> > content in an un-typed manner.
>> > 
>> > -----Original Message-----
>> > From: Ganga Sah [mailto:ganga_sah@yahoo.com]
>> > Sent: Monday, January 05, 2004 9:47 AM
>> > To: xmlbeans-dev@xml.apache.org
>> > Subject: get/set methods for <xsd:any> element
>> > 
>> > 
>> > I am unable to find/use get(set) methods in
>> xmlbeans
>> > generated Java code for <xsd:any> element?
>> > 
>> > -ganga



- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-dev-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/