xml-xmlbeans-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cezar Andrei" <ce...@bea.com>
Subject RE: get/set methods for <xsd:any> element
Date Sat, 14 Feb 2004 10:47:58 GMT
Another possible solution is to have a helper class for doing all of this, and we should not
forget the attribute wildcards. A helper class would give us more room to play with usability
before we iron it in the XmlObject API.

Anybody interested in contributing this piece?

Cezar

> -----Original Message-----
> From: Wolfgang Hoschek [mailto:whoschek@lbl.gov]
> Sent: Thursday, February 12, 2004 5:45 PM
> To: xmlbeans-dev@xml.apache.org
> Subject: RE: get/set methods for <xsd:any> 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 <ericvas@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 <ericvas@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/
> 
> 

- ---------------------------------------------------------------------
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/


Mime
View raw message