You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Soumya <so...@yahoo.co.in> on 2010/04/29 13:09:42 UTC
XmlBean object confusion
Hi guys,
I came across a strange issue today for which I am having serious doubts about my Java skills!!.. if this is something very obvious and I am posing a blind eye to it please do open my eyes!
I have an xsd say type1.xsd which has an element <xml_element> at the top level.
xml from it would look like
<xml_element>
<request>
<customer>
.....
</xml_element>
Now I have another xsd which has the same top level elements xml_element and request but different inside. xml complying to it would look like
<xml_element>
<request>
<transaction>
.....
</xml_element>
So you can see above that the 2 top level elements <xml_element> and <request> are the same.
Now I use Xmlbeans to generate 2 different jars out of it -
type1.xsd has the following document object - com.company.type.one.XmlElementDocument
type2.xsd has the following document object - com.company.type.two.XmlElementDocument
Kindly note the packages are different and so are fully qualified classnames. Also they are in 2 different jars type1.jar and type2.jar
Now when I load my Application and try to use
com.company.type.one.XmlElementDocument.Factory.parse("somexml") - where "somexml" is actually of type type1.xsd it errors out telling xml not of type <xml_element> - shocking!! it works fine standalone. But when I put both jars together it errors out!!
if i remove type2.jar from the application it works fine happily again.
Ideally since the package names are different shouldnt the 2 XmlElementDocument s be identifiable separately.. after all that's why java is so good with fully qualified classnames.
Please suggest if you have faced similar issue.
thanks in advance.
Soumya
RE: XmlBean object confusion
Posted by Peter Keller <pk...@globalphasing.com>.
On Thu, 29 Apr 2010, Wing Yew Poon wrote:
> (Peter, the plural of schema is schemata.)
You are absolutely right of course. It seems my education wasn't quite
classical enough ;-)
Regards,
Peter.
--
Peter Keller Tel.: +44 (0)1223 353033
Global Phasing Ltd., Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: XmlBean object confusion
Posted by Soumya <so...@yahoo.co.in>.
Thanks both Peter and Wing!!
Now I guess it makes all sense. Thanks for pointing out the XML Type system of loading the schemas concept. I was assuming it is same as Java class loading which is evidently not the case. Namespace is really important after all!!
Best Regards,
Soumya
________________________________
From: Wing Yew Poon <wi...@oracle.com>
To: user@xmlbeans.apache.org
Sent: Thu, 29 April, 2010 5:33:53 PM
Subject: RE: XmlBean object confusion
Soumya,
Peter was right. Your problem is that both schemas have
the same target namespace (i.e., no namespace), so you can't use them together,
The second schema happened to be loaded after the first and shadowed it. Thus
when you tried to parse the xml instance of the first schema, XMLBeans did not
recognize it.
You should use namespaces in your schemas to
distinguish them. Or else combine them in one schema as Peter
suggested.
- Wing Yew
(Peter, the plural of schema is
schemata.)
________________________________
From: Soumya [mailto:soumya_ssp@yahoo.co.in]
Sent: Thursday, April 29, 2010 9:05 AM
To: user@xmlbeans.apache.org
Subject: Re: XmlBean object
confusion
Dear
Peter,
thanks for your prompt reply.
My apologies for not furnishing all
details in the first instance
So here is the error trail
-
org.apache.xmlbeans.XmlException: XML object is not of type D=xml_element
at
org.apache.xmlbeans.impl.store.Root.autoTypedDocument(Root.java:445)
at
org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1049)
at
org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1039)
at
org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1059)
at
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:214)
at com.company.type.one.XmlElementDocument$Factory.parse(Unknown
Source)
So as you see it was using the correct package but still says it
cannot recognise it.
As for target namespace we didnt use any. i.e. used
default.
type1.xsd -
package used is com.company.type.one
<xs:element
name="xml_element">
<xs:complexType>
<xs:sequence
maxOccurs="1">
<xs:choice>
<xs:element
name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="customer"
type="customerT"/>
<xs:element nam
............
...................................
/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
type2.xsd
type2.xsd -
package used is com.company.type.two
<xs:element
name="xml_element">
<xs:complexType>
<xs:sequence
maxOccurs="1">
<xs:choice>
<xs:element
name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="transaction"
type="transactionT"/>
<xs:element nam
............
...................................
/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
Sample
XML that failed -
<xml_element>
<request
success="y">
<customer>
<range_num>0</range_num>
..............
..............
</customer>
</request>
</xml_element>
So as u see 2 different xsds
that have same top level tags and corresponding Document classes, but different
package names. so 2 different jars.
Still it errored out.
I have fixed
the issue by combining the 2 xsds into one and having a common package
name.
But still was trying to dig into the actual reason for the issue I
faced!
Thanks in advance.
Soumya
________________________________
From: Peter Keller
<pk...@globalphasing.com>
To: user@xmlbeans.apache.org
Sent: Thu, 29 April, 2010 2:02:57
PM
Subject: Re: XmlBean object
confusion
Dear Soumya,
Your assumption that this has
something to do with the Java typesystem may be wrong, but since you haven't
given us the actual text of the error message we have no way of
knowing.
You have also given us very little information about how you
have written your schemae, but one thing occurs to me: do they both have the
same target namespace? If they do, there may be a conflict between the
definitions of the root elements, and the problem is with the XML type system
rather than the Java one (see the XMLBeans javadoc for
org.apache.xmlbeans.SchemaType). If this is the problem, and you need to keep a
single target namespace, you could design your way out of this problem by
merging the two schemae into a single one: use either <xsd:choice> or
derivation from a common supertype to allow the new single schema to describe
both types of document.
Regards,
Peter.
On Thu, 29 Apr 2010,
Soumya wrote:
> Date: Thu, 29 Apr 2010 16:39:42 +0530 (IST)
>
From: Soumya <so...@yahoo.co.in>
>
Reply-To: user@xmlbeans.apache.org
>
To: user@xmlbeans.apache.org
>
Subject: XmlBean object confusion
>
> Hi guys,
>
> I
came across a strange issue today for which I am having serious doubts about my
Java skills!!..
> if this is something very obvious and I am posing a
blind eye to it please do open my eyes!
>
> I have an xsd say
type1.xsd which has an element <xml_element> at the top level.
> xml
from it would look like
> <xml_element>
>
<request>
>
<customer>
> .....
> </xml_element>
>
> Now
I have another xsd which has the same top level elements xml_element and request
but different
> inside. xml complying to it would look like
>
<xml_element>
> <request>
>
<transaction>
> .....
>
</xml_element>
>
> So you can see above that the 2 top level
elements <xml_element> and <request> are the same.
> Now I use
Xmlbeans to generate 2 different jars out of it -
> type1.xsd has the
following document object - com.company.type.one.XmlElementDocument
>
> type2.xsd has the following document object -
com.company.type.two.XmlElementDocument
>
> Kindly note the
packages are different and so are fully qualified classnames. Also they are in
2
> different jars type1.jar and type2.jar
>
> Now when I
load my Application and try to use
>
com.company.type.one.XmlElementDocument.Factory.parse("somexml") - where
"somexml" is actually of
> type type1.xsd it errors out telling xml not of
type <xml_element> - shocking!! it works fine
> standalone. But when
I put both jars together it errors out!!
>
> if i remove type2.jar
from the application it works fine happily again.
>
> Ideally since
the package names are different shouldnt the 2 XmlElementDocument s be
identifiable
> separately.. after all that's why java is so good with
fully qualified classnames.
> Please suggest if you have faced similar
issue.
> thanks in advance.
> Soumya
>
>
>
-- Peter Keller
Tel.: +44
(0)1223 353033
Global Phasing Ltd.,
Fax.: +44 (0)1223
366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United
Kingdom
---------------------------------------------------------------------
To
unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For
additional commands, e-mail: user-help@xmlbeans.apache.org
RE: XmlBean object confusion
Posted by Wing Yew Poon <wi...@oracle.com>.
Soumya,
Peter was right. Your problem is that both schemas have the same target namespace (i.e., no namespace), so you can't use them together, The second schema happened to be loaded after the first and shadowed it. Thus when you tried to parse the xml instance of the first schema, XMLBeans did not recognize it.
You should use namespaces in your schemas to distinguish them. Or else combine them in one schema as Peter suggested.
- Wing Yew
(Peter, the plural of schema is schemata.)
_____
From: Soumya [mailto:soumya_ssp@yahoo.co.in]
Sent: Thursday, April 29, 2010 9:05 AM
To: user@xmlbeans.apache.org
Subject: Re: XmlBean object confusion
Dear Peter,
thanks for your prompt reply.
My apologies for not furnishing all details in the first instance
So here is the error trail -
org.apache.xmlbeans.XmlException: XML object is not of type D=xml_element
at org.apache.xmlbeans.impl.store.Root.autoTypedDocument(Root.java:445)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1049)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1039)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1059)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:214)
at com.company.type.one.XmlElementDocument$Factory.parse(Unknown Source)
So as you see it was using the correct package but still says it cannot recognise it.
As for target namespace we didnt use any. i.e. used default.
type1.xsd -
package used is com.company.type.one
<xs:element name="xml_element">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="customer" type="customerT"/>
<xs:element nam ............
................................... />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
type2.xsd
type2.xsd -
package used is com.company.type.two
<xs:element name="xml_element">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="transaction" type="transactionT"/>
<xs:element nam ............
................................... />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
Sample XML that failed -
<xml_element>
<request success="y">
<customer>
<range_num>0</range_num>
..............
..............
</customer>
</request>
</xml_element>
So as u see 2 different xsds that have same top level tags and corresponding Document classes, but different package names. so 2 different jars.
Still it errored out.
I have fixed the issue by combining the 2 xsds into one and having a common package name.
But still was trying to dig into the actual reason for the issue I faced!
Thanks in advance.
Soumya
_____
From: Peter Keller <pk...@globalphasing.com>
To: user@xmlbeans.apache.org
Sent: Thu, 29 April, 2010 2:02:57 PM
Subject: Re: XmlBean object confusion
Dear Soumya,
Your assumption that this has something to do with the Java typesystem may be wrong, but since you haven't given us the actual text of the error message we have no way of knowing.
You have also given us very little information about how you have written your schemae, but one thing occurs to me: do they both have the same target namespace? If they do, there may be a conflict between the definitions of the root elements, and the problem is with the XML type system rather than the Java one (see the XMLBeans javadoc for org.apache.xmlbeans.SchemaType). If this is the problem, and you need to keep a single target namespace, you could design your way out of this problem by merging the two schemae into a single one: use either <xsd:choice> or derivation from a common supertype to allow the new single schema to describe both types of document.
Regards,
Peter.
On Thu, 29 Apr 2010, Soumya wrote:
> Date: Thu, 29 Apr 2010 16:39:42 +0530 (IST)
> From: Soumya <HYPERLINK "mailto:soumya_ssp@yahoo.co.in"soumya_ssp@yahoo.co.in>
> Reply-To: HYPERLINK "mailto:user@xmlbeans.apache.org"user@xmlbeans.apache.org
> To: HYPERLINK "mailto:user@xmlbeans.apache.org"user@xmlbeans.apache.org
> Subject: XmlBean object confusion
>
> Hi guys,
>
> I came across a strange issue today for which I am having serious doubts about my Java skills!!..
> if this is something very obvious and I am posing a blind eye to it please do open my eyes!
>
> I have an xsd say type1.xsd which has an element <xml_element> at the top level.
> xml from it would look like
> <xml_element>
> <request>
> <customer>
> .....
> </xml_element>
>
> Now I have another xsd which has the same top level elements xml_element and request but different
> inside. xml complying to it would look like
> <xml_element>
> <request>
> <transaction>
> .....
> </xml_element>
>
> So you can see above that the 2 top level elements <xml_element> and <request> are the same.
> Now I use Xmlbeans to generate 2 different jars out of it -
> type1.xsd has the following document object - com.company.type.one.XmlElementDocument
>
> type2.xsd has the following document object - com.company.type.two.XmlElementDocument
>
> Kindly note the packages are different and so are fully qualified classnames. Also they are in 2
> different jars type1.jar and type2.jar
>
> Now when I load my Application and try to use
> com.company.type.one.XmlElementDocument.Factory.parse("somexml") - where "somexml" is actually of
> type type1.xsd it errors out telling xml not of type <xml_element> - shocking!! it works fine
> standalone. But when I put both jars together it errors out!!
>
> if i remove type2.jar from the application it works fine happily again.
>
> Ideally since the package names are different shouldnt the 2 XmlElementDocument s be identifiable
> separately.. after all that's why java is so good with fully qualified classnames.
> Please suggest if you have faced similar issue.
> thanks in advance.
> Soumya
>
>
>
-- Peter Keller Tel.: +44 (0)1223 353033
Global Phasing Ltd., Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom
---------------------------------------------------------------------
To unsubscribe, e-mail: HYPERLINK "mailto:user-unsubscribe@xmlbeans.apache.org"user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: HYPERLINK "mailto:user-help@xmlbeans.apache.org"user-help@xmlbeans.apache.org
Re: XmlBean object confusion
Posted by Soumya <so...@yahoo.co.in>.
Dear Peter,
thanks for your prompt reply.
My apologies for not furnishing all details in the first instance
So here is the error trail -
org.apache.xmlbeans.XmlException: XML object is not of type D=xml_element
at org.apache.xmlbeans.impl.store.Root.autoTypedDocument(Root.java:445)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1049)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1039)
at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1059)
at org.apache.xmlbeans.impl.schema.SchemaTypeLoaderBase.parse(SchemaTypeLoaderBase.java:214)
at com.company.type.one.XmlElementDocument$Factory.parse(Unknown Source)
So as you see it was using the correct package but still says it cannot recognise it.
As for target namespace we didnt use any. i.e. used default.
type1.xsd -
package used is com.company.type.one
<xs:element name="xml_element">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="customer" type="customerT"/>
<xs:element nam ............
................................... />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
type2.xsd
type2.xsd -
package used is com.company.type.two
<xs:element name="xml_element">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="request">
<xs:complexType>
<xs:sequence maxOccurs="1">
<xs:choice>
<xs:element name="transaction"
type="transactionT"/>
<xs:element nam ............
...................................
/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
....................
....................
</xs:element>
Sample XML that failed -
<xml_element>
<request success="y">
<customer>
<range_num>0</range_num>
..............
..............
</customer>
</request>
</xml_element>
So as u see 2 different xsds that have same top level tags and corresponding Document classes, but different package names. so 2 different jars.
Still it errored out.
I have fixed the issue by combining the 2 xsds into one and having a common package name.
But still was trying to dig into the actual reason for the issue I faced!
Thanks in advance.
Soumya
________________________________
From: Peter Keller <pk...@globalphasing.com>
To: user@xmlbeans.apache.org
Sent: Thu, 29 April, 2010 2:02:57 PM
Subject: Re: XmlBean object confusion
Dear Soumya,
Your assumption that this has something to do with the Java typesystem may be wrong, but since you haven't given us the actual text of the error message we have no way of knowing.
You have also given us very little information about how you have written your schemae, but one thing occurs to me: do they both have the same target namespace? If they do, there may be a conflict between the definitions of the root elements, and the problem is with the XML type system rather than the Java one (see the XMLBeans javadoc for org.apache.xmlbeans.SchemaType). If this is the problem, and you need to keep a single target namespace, you could design your way out of this problem by merging the two schemae into a single one: use either <xsd:choice> or derivation from a common supertype to allow the new single schema to describe both types of document.
Regards,
Peter.
On Thu, 29 Apr 2010, Soumya wrote:
> Date: Thu, 29 Apr 2010 16:39:42 +0530 (IST)
> From: Soumya <so...@yahoo.co.in>
> Reply-To: user@xmlbeans.apache.org
> To: user@xmlbeans.apache.org
> Subject: XmlBean object confusion
>
> Hi guys,
>
> I came across a strange issue today for which I am having serious doubts about my Java skills!!..
> if this is something very obvious and I am posing a blind eye to it please do open my eyes!
>
> I have an xsd say type1.xsd which has an element <xml_element> at the top level.
> xml from it would look like
> <xml_element>
> <request>
> <customer>
> .....
> </xml_element>
>
> Now I have another xsd which has the same top level elements xml_element and request but different
> inside. xml complying to it would look like
> <xml_element>
> <request>
> <transaction>
> .....
> </xml_element>
>
> So you can see above that the 2 top level elements <xml_element> and <request> are the same.
> Now I use Xmlbeans to generate 2 different jars out of it -
> type1.xsd has the following document object - com.company.type.one.XmlElementDocument
>
> type2.xsd has the following document object - com.company.type.two.XmlElementDocument
>
> Kindly note the packages are different and so are fully qualified classnames. Also they are in 2
> different jars type1.jar and type2.jar
>
> Now when I load my Application and try to use
> com.company.type.one.XmlElementDocument.Factory.parse("somexml") - where "somexml" is actually of
> type type1.xsd it errors out telling xml not of type <xml_element> - shocking!! it works fine
> standalone. But when I put both jars together it errors out!!
>
> if i remove type2.jar from the application it works fine happily again.
>
> Ideally since the package names are different shouldnt the 2 XmlElementDocument s be identifiable
> separately.. after all that's why java is so good with fully qualified classnames.
> Please suggest if you have faced similar issue.
> thanks in advance.
> Soumya
>
>
>
-- Peter Keller Tel.: +44 (0)1223 353033
Global Phasing Ltd., Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: XmlBean object confusion
Posted by Peter Keller <pk...@globalphasing.com>.
Dear Soumya,
Your assumption that this has something to do with the Java typesystem may
be wrong, but since you haven't given us the actual text of the error
message we have no way of knowing.
You have also given us very little information about how you have written
your schemae, but one thing occurs to me: do they both have the same target
namespace? If they do, there may be a conflict between the definitions of
the root elements, and the problem is with the XML type system rather than
the Java one (see the XMLBeans javadoc for org.apache.xmlbeans.SchemaType).
If this is the problem, and you need to keep a single target namespace, you
could design your way out of this problem by merging the two schemae into a
single one: use either <xsd:choice> or derivation from a common supertype to
allow the new single schema to describe both types of document.
Regards,
Peter.
On Thu, 29 Apr 2010, Soumya wrote:
> Date: Thu, 29 Apr 2010 16:39:42 +0530 (IST)
> From: Soumya <so...@yahoo.co.in>
> Reply-To: user@xmlbeans.apache.org
> To: user@xmlbeans.apache.org
> Subject: XmlBean object confusion
>
> Hi guys,
>
> I came across a strange issue today for which I am having serious doubts about my Java skills!!..
> if this is something very obvious and I am posing a blind eye to it please do open my eyes!
>
> I have an xsd say type1.xsd which has an element <xml_element> at the top level.
> xml from it would look like
> <xml_element>
> ��� <request>
> ��� ��� <customer>
> .....
> </xml_element>
>
> Now I have another xsd which has the same top level elements xml_element and request but different
> inside. xml complying to it would look like
> <xml_element>
> ��� <request>
> ��� ��� <transaction>
> .....
> </xml_element>
>
> So you can see above that the 2 top level elements <xml_element> and <request> are the same.
> Now I use Xmlbeans to generate 2 different jars out of it -
> type1.xsd has the following document object - com.company.type.one.XmlElementDocument
>
> type2.xsd has the following document object - com.company.type.two.XmlElementDocument
>
> Kindly note the packages are different and so are fully qualified classnames. Also they are in 2
> different jars type1.jar and type2.jar
>
> Now when I load my Application and try to use
> com.company.type.one.XmlElementDocument.Factory.parse("somexml") - where "somexml" is actually of
> type type1.xsd it errors out telling xml not of type <xml_element> - shocking!! it works fine
> standalone. But when I put both jars together it errors out!!
>
> if i remove type2.jar from the application it works fine happily again.
>
> Ideally since the package names are different shouldnt the 2 XmlElementDocument s be identifiable
> separately.. after all that's why java is so good with fully qualified classnames.
> Please suggest if you have faced similar issue.
> thanks in advance.
> Soumya
>
>
>
--
Peter Keller Tel.: +44 (0)1223 353033
Global Phasing Ltd., Fax.: +44 (0)1223 366889
Sheraton House,
Castle Park,
Cambridge CB3 0AX
United Kingdom