[xsd-users] XSD : How to set attributes values in children element type?

Klaim mjklaim at gmail.com
Tue Nov 23 11:53:00 EST 2010


Hi,

I already posted the question some days ago there :
http://stackoverflow.com/questions/4199180/xsd-how-to-set-attributes-values-in-children-element-type

But I only have one answer and it don't work in the end. :/

Here is a copy-paste of the question  :
-------------------------------------------------------------------------------------------------

In an xsd file I have this element base type :

<xs:complexType name="event" abstract="true" >
    <xs:attribute name="move" type="aos:move_ref" use="required" />
    <xs:attribute name="type" type="aos:event_type" use="required" />
</xs:complexType>

And I want to define the value of the type attribute in the children types,
so I tried this :

<xs:complexType name="signal" >
    <xs:complexContent>
      <xs:extension base="aos:event">
        <xs:attribute name="type" type="aos:event_type" fixed="signal" />
        <xs:attribute name="source" type="aos:signal_source" use="required" />
      </xs:extension>
    </xs:complexContent>
 </xs:complexType>

Visual Studio don't seem to bother but CodeSynthesis C++ code
generator<http://www.codesynthesis.com/products/xsd> don't
seem to agree :

error: attribute 'type' is already defined in base

How should I write this? I just want the value of the type attribute to be
specific to each different child type.

edit ----

To make the question more clear, I'll write the same thing I want to do but
in C++.

Here is the base class :

class Event
{
public:

   std::string name() const { return m_name; }

protected:

   // we need the child class to set the name
   Event( const std::string& name ) : m_name( name ) {}

   // it's a base class
   virtual ~Event(){}

private:

   std::string m_name;

};

Now, one of the children could be implemented like this :

class Signal : public Event
{
public:

   Signal() : Event( "signal" ){}

};

As you can see, the child class define the values of attributes that are
defined by the base class. Is it even possible to express in xsd?


------------------------------
Now, I think I'm not aware of some things in xsd and that might make me
think that this should be possible.
If there are xsd experts around, I'd like to know how to achieve something
similar?

I can't think of any solution and for the moment I'm using a test project to
try to make codesynthesis do what I want (to have a common interface with a
specific value by child type).
I've been stuck on this for a lot of time and can't release my xml-based
language without fixing this (or I'll have to totally refactor the way I'm
using xsd types).

Any idea?

Thanks for your time.

Klaim aka J. Lamotte


More information about the xsd-users mailing list