You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by "Dunlop, Aaron" <aa...@transcore.com> on 2004/05/29 01:19:20 UTC

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/