Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » idrefs and holders
idrefs and holders [message #73037] Wed, 12 September 2007 11:09 Go to next message
Eclipse UserFriend
Originally posted by: creckord.uni-kassel.de

Hi all,

I have two questions regarding binding of IDREF and IDREFS.

1. Is there a way to generally bind IDREF/S to references (to EObject or the like) instead of String attributes? I have a schema here that
makes frequent use of IDREFs without the referenced elements having a common super type, so I don't have any real type to use with
ecore:reference. By accident I found out that XSD will bind IDREFs to EObject if the type specified by ecore:reference doesn't exist in the
schema, so currently I have it working by using ecore:reference="ecore:EObject". But I'm wondering if there's a better way because this
seems a bit like exploiting a "loophole".

2. I have quite a few elements of the following form:

<xs:complexType name="Accessory_occurrence">
<xs:sequence>
<xs:element name="Reference_element" type="xs:IDREFS"
ecore:reference="kbl:Connector_occurrence"/>
...
</xs:sequence>
</xs:complexType>

XSD will generate a holder class ReferenceElementHolder for this. While I can see that this makes sense in case of the element having an
upper bound > 1, I don't think it is necessary here. And it really makes the API ugly because I have quite a lot of those to deal with. So
I'd like to know if there's an easy way to get rid of those holders in this case or if I'd have to write custom XMLSave and XMLHandler classes.

Thanks,
Carsten
Re: idrefs and holders [message #73055 is a reply to message #73037] Wed, 12 September 2007 11:33 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Carsten,

Comments below.

Carsten Reckord wrote:
> Hi all,
>
> I have two questions regarding binding of IDREF and IDREFS.
>
> 1. Is there a way to generally bind IDREF/S to references (to EObject
> or the like) instead of String attributes? I have a schema here that
> makes frequent use of IDREFs without the referenced elements having a
> common super type, so I don't have any real type to use with
> ecore:reference.
Sure. Using ecore:reference="xsd:anyType" and that will turn into an
EObject reference.
> By accident I found out that XSD will bind IDREFs to EObject if the
> type specified by ecore:reference doesn't exist in the schema, so
> currently I have it working by using ecore:reference="ecore:EObject".
> But I'm wondering if there's a better way because this seems a bit
> like exploiting a "loophole".
>
> 2. I have quite a few elements of the following form:
>
> <xs:complexType name="Accessory_occurrence">
> <xs:sequence>
> <xs:element name="Reference_element" type="xs:IDREFS"
> ecore:reference="kbl:Connector_occurrence"/>
> ...
> </xs:sequence>
> </xs:complexType>
>
> XSD will generate a holder class ReferenceElementHolder for this.
> While I can see that this makes sense in case of the element having an
> upper bound > 1, I don't think it is necessary here. And it really
> makes the API ugly because I have quite a lot of those to deal with.
> So I'd like to know if there's an easy way to get rid of those holders
> in this case or if I'd have to write custom XMLSave and XMLHandler
> classes.
You'd have to customize. There'd be no way to tell the difference
between a repeating element of type IDREF verses a single element of
type IDREFS; both results in a multi-valued EReference and this will
always introduce a result like the former. Couldn't you make it an
attribute instead of an element. Failing that, you'll need to
specialize the XMLSaveImpl to save a single element; I suspect the
XMLHandler might just do the right thing on its own...
>
> Thanks,
> Carsten
Re: idrefs and holders [message #602621 is a reply to message #73037] Wed, 12 September 2007 11:33 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Carsten,

Comments below.

Carsten Reckord wrote:
> Hi all,
>
> I have two questions regarding binding of IDREF and IDREFS.
>
> 1. Is there a way to generally bind IDREF/S to references (to EObject
> or the like) instead of String attributes? I have a schema here that
> makes frequent use of IDREFs without the referenced elements having a
> common super type, so I don't have any real type to use with
> ecore:reference.
Sure. Using ecore:reference="xsd:anyType" and that will turn into an
EObject reference.
> By accident I found out that XSD will bind IDREFs to EObject if the
> type specified by ecore:reference doesn't exist in the schema, so
> currently I have it working by using ecore:reference="ecore:EObject".
> But I'm wondering if there's a better way because this seems a bit
> like exploiting a "loophole".
>
> 2. I have quite a few elements of the following form:
>
> <xs:complexType name="Accessory_occurrence">
> <xs:sequence>
> <xs:element name="Reference_element" type="xs:IDREFS"
> ecore:reference="kbl:Connector_occurrence"/>
> ...
> </xs:sequence>
> </xs:complexType>
>
> XSD will generate a holder class ReferenceElementHolder for this.
> While I can see that this makes sense in case of the element having an
> upper bound > 1, I don't think it is necessary here. And it really
> makes the API ugly because I have quite a lot of those to deal with.
> So I'd like to know if there's an easy way to get rid of those holders
> in this case or if I'd have to write custom XMLSave and XMLHandler
> classes.
You'd have to customize. There'd be no way to tell the difference
between a repeating element of type IDREF verses a single element of
type IDREFS; both results in a multi-valued EReference and this will
always introduce a result like the former. Couldn't you make it an
attribute instead of an element. Failing that, you'll need to
specialize the XMLSaveImpl to save a single element; I suspect the
XMLHandler might just do the right thing on its own...
>
> Thanks,
> Carsten


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:idrefs and holders
Next Topic:Proper way to get the default value for an attribute
Goto Forum:
  


Current Time: Thu Apr 25 06:05:32 GMT 2024

Powered by FUDForum. Page generated in 0.03016 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top