You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Kevin Krouse <kk...@bea.com> on 2004/06/02 02:36:32 UTC

RE: Concrete object types from XPath?

Hi Aaron,

I just tried this and I noticed the same thing when the <request:applicationHeader> element inside the header doesn't correspond to a element in your schema, but is a simple/complex type in the schema instead.  When I first repro'd your scenario I was using a simpleType named "applicationHeader."  Then I added an global "applicationHeader" element to the schema which was of type "applicationHeader" and the selectPath returned the proper sub-class.

Is that what is happening in your schema?

--k

-----Original Message-----
From: Dunlop, Aaron [mailto:aaron.dunlop@transcore.com]
Sent: Friday, May 28, 2004 4:19 PM
To: xmlbeans-user@xml.apache.org
Subject: Concrete object types from XPath?


Is it possible to get a concrete type from an XPath expression into an xs:any?

Given the following XML:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mileage="http://www.tcore.com/TcoreMileage.xsd" xmlns:request="http://www.tcore.com/TcoreRequest.xsd">
  <soap:Header>
    <request:applicationHeader>
...

and having compiled the schemas defining the soap envelope and the relevant headers using SCOMP,
It seems I should be able to do:

XmlObject header;
String xpath = "declare namespace request='http://www.tcore.com/TcoreRequest.xsd' .//request:applicationHeader";
...
ApplicationHeader applicationHeader = (ApplicationHeader) header.selectPath(xpath)[0];

But that causes a ClassCastException (the first object in the array returned from selectPath is of type XmlAnyTypeImpl instead of ApplicationHeaderImpl)

--------------------------
I can make it work with:

ApplicationHeader applicationHeader = ApplicationHeader.Factory.parse(header.selectPath(xpath)[0].newInputStream());

but that seems terribly inelegant, since it results in re-parsing the header. It does prove, however that the ApplicationHeader class is available at runtime and working properly.
-------------------------

I have the same issue in the SOAP body of course, since it is also defined as an xs:any. And in fact it's a bit worse there, because I don't know which of a number of derived types might be in the body. And using the factory of the generated superclass to parse the body results in an instance of the superclass, rather than an instance of the appropriate derived class. The way I read the javadocs for XmlObject, parsing using the factory of any superclass should work (e.g., XmlObject.factory.parse() should return an instance of the derived subclass). But perhaps this doesn't apply if we're parsing an element instead of the complete document?

Any ideas what I'm doing wrong?

Thanks in advance,
Aaron Dunlop

-----------------------------------------------------------------------
Aaron Dunlop
Product Development Engineer
TransCore
Email: aaron.dunlop@transcore.com




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


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