Radu,

Thanks for your comments. To complicate matters, I believe I ran into
the issue affecting xmlbeans when executing within Axis2, namely the
class loader problem
(http://issues.apache.org/jira/browse/XMLBEANS-310). My code worked fine
isolated in a Junit test, but fell apart on the server.

You are quite correct about the xml hierarchy and your code snippet
below looks sufficiently succinct for me.

Cheers, Des



-----Original Message-----
From: Radu Preotiuc-Pietro [mailto:[EMAIL PROTECTED] 
Sent: 22 June 2007 22:33
To: user@xmlbeans.apache.org
Subject: RE: Getting concrete object from Any

My opinion is that it will just work even if you have multiple jars,
must be something else that complicates David's case (substitution
groups).

However, Desmond, it seems to me that what you suggest is exactly what
XmlBeans is doing today. Note that in your Schema, the <any> wildcard is
a child of the <myChild> element, so obviously you can't replace
<myChild> with <daughter>, but you need to have <daughter> as a child,
like so:

<myElem>
  <myChild>
    <daughter>britney spears</daughter>
  </myChild>
</myElem>

Or, you need to change your Schema.

Now if you do

MyChildType myChild = myElem.getMyChild(); XmlObject instance =
myChild.selectChildren("", "daughter")[0];

you will see that "instance" already has the right type.

Radu

On Wed, 2007-06-20 at 15:31 +0200, Desmond Whewell (CV/ETL) wrote: 
> David,
> 
> Thank you for your help. Mercifully, my schemas *are* compiled in one 
> pass and *do* end up in 1 jar file. I tried this:
> 
>     XmlObject[] objs = myChild.selectChildren(QNAME_DAUGHTER);
>     Daughter daughter = null;
>     for (int i = 0; i < objs.length; i++) {
>         XmlObject myObj =  objs[i];
>                 
>         daughter =
(Daughter)Daughter.Factory.newInstance().set(myObj);
>         break;
>     }
>     if (daughter != null) {
>         int j = daughter.getAge();        
>     .....etc.....
> 
> or something very similar, and it worked!
> 
> As an xmlbeans newbie, I think the manipulation of 'Any's could be 
> made easier. It's a pity I couldn't have done something like:
> 
>     Daughter daughter = myElem.getMyChild().refine(Daughter.type);
>     if (daughter != null) {
>     .....etc.....
> 
> After all, doesn't xmlbeans already have all of the information 
> required to extract the concrete from the Any?
> 
> Thanks again,
> 
> Des
> 
> -----Original Message-----
> From: David Jencks [mailto:[EMAIL PROTECTED]
> Sent: 20 June 2007 12:56
> To: user@xmlbeans.apache.org
> Subject: Re: Getting concrete object from Any
> 
> 1. IIUC your sample document should look like <myElem xmlns="mine"> 
> <myChlid> <daughter>foo</daughter> </myChild> </myElem>
> 
> 2. Try XmlObject.selectChildren(QNameSet desiredQNames);
> 
> If all your schemas are compiled at once into one jar I think this  
> will return the desired XmlObjects as the types you expect.   
> Otherwise if you get a plain XmlObject you may have to copy and call
> changeType(desiredSchemaType) on them.  When I do this I find that 
> trying to call changeType without making a new copy usually doesn't 
> work, but I'm also trying to glue together a lot of schema type 
> systems from several jars, so it may work better if all your schemas 
> are compiled at once.
> 
> hope this helps
> david jencks
> 
> On Jun 20, 2007, at 5:39 AM, Desmond Whewell (CV/ETL) wrote:
> 
> > Sorry about Yet-Another-Any question, but this is my first 
> > expedition in Xmlbeans and I have seached the documentation and 
> > Javadocs and I'm still banging my head against a brick wall.
> >
> > Suppose I have a schema with an element, 'myElem', say. One of the 
> > child elements, 'myChild', is defined as:
> >
> >     <xs:element name="myChild" type="MyChildType" minOccurs="0" />
> >     <xs:complexType name="MyChildType">
> >         <xs:sequence>
> >           <xs:any namespace="##any" processContents="lax"
> > maxOccurs="unbounded" />
> >         </xs:sequence>
> >     </xs:complexType>
> >
> > I can get at MyChild by:
> >
> >     MyChildType myChild = myElem.getMyChild();
> >
> > But, and you all know what's coming, how do I get the object that is
> > *actually* being carried in the place of the Any? I have tried using

> > XmlCursors to navigate to the object, but I really don't want to 
> > have to disassemble the XmlObject, what I really want is to get back

> > to the
> 
> > cosy world of gets and sets on the concrete objects.
> >
> > So, if I had a xml fragement that looked like:
> >
> >     <myElem>
> >         <daughter>britney spears</daughter>
> >     </myElem>
> >
> > What is the cleanest way of extracting the XmlObject and creating 
> > the associated 'daughter' xmlbean so that I can go back to :
> >
> >     daughter.getAge();
> >
> > Assume that 'daughter' is the only element type that I'm prepared to

> > accept and that other elements will be rejected by the surrounding 
> > application as 'not supported'.
> >
> > Thanks for any help.
> >
> > Cheers, Des
> >
> > --------------------------------------------------------------------
> > - To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to