[xsd-users] Question about ID/IDREF
Vera Mickael
vera.mickael at free.fr
Mon Sep 12 09:55:13 EDT 2005
Boris Kolpackov a écrit :
> Mickael,
>
> Vera Mickael <vera.mickael at free.fr> writes:
>
>
>>Each time I use ID and IDREF, the method in the generated
>>model for the attribute that uses IDREF returns a
>>java.lang.Object. This makes the generated model very
>>difficult to use.
>
>
> Ok, you mean you have to manually cast it to a concrete type.
>
>
>
>>Does xsd generate the same (a method that returns void *) ?
>
>
> At the moment, xsd generates a member function that returns
> a pointer to a type that all generated types inherit from
> (similar to java.lang.Object). You have to cast this pointer
> to a concrete one.
>
>
>>Or is there a way to specify the type of the element
>>referenced by IDREF, by annotations for example ?
>
>
> Not at the moment but we have plans to do so. The idea is
> to have an attribute that you can use to specify the "real
> type" of IDREF, e.g.:
>
> <xsd:complexType name="author">
>
> ...
>
> <xsd:attribute name="recommends"
> type="xsd:IDREF"
> ref-type="lib:book"/>
> </xsd:complexType>
>
>
> <xsd:complexType name="book">
> <xsd:sequence>
> <xsd:element name="title" type="xsd:string"/>
>
> ...
>
> </xsd:sequence>
>
> <xsd:attribute name="id" type="xsd:ID" use="required"/>
> </xsd:complexType>
>
>
> Then you will be able to write something like this:
>
> author a = ...
>
> cerr << a.recommends ()->title () << endl;
>
>
> Would you be interested in something like this?
>
> -boris
>
Your solution with ref-type attribute is better than using
annotations :-)
Yes I would be interested in such a feature, I'm kind on
statically typed programmation and JAXB really lacks about
this. It makes it really difficult to change the schema. It
would be a feature usefull for everybody.
This question raises another one.
I'd like to use xsd as a simple serialization tool, my point
of view is model centric : I know the model I want (thus the
C++ code I need) then I write the corresponding XML schema.
How would you write a schema for a collection of IDREF
without using an intermediate element ? If I use your
exemple, I'd like to have a method like this :
std::vector<book *> &
author::recommends();
My only idea is to create a element bookRef with an
attribute referencing a book and use this element bookRef in
a sequence in the element author. I guess that I would have
the following code that isn't as elegant as the previous :
std::vector<bookRef> &
author::recommends();
Thanks for your answer,
Mickaël
More information about the xsd-users
mailing list