Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3397830
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:34:33+00:00 2026-05-18T04:34:33+00:00

In an xsd file I have this element base type : <xs:complexType name=event abstract=true

  • 0

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 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:34:33+00:00Added an answer on May 18, 2026 at 4:34 am

    To derive a type and fix a value, use a restriction:

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

    From reading the spec, I would have expected that you couldn’t add attributes in a restriction unless the base type had an attribute wildcard, but the W3C XSD validator accepts the above. If you run into problems, you can break up the definition into a restriction and an extension:

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

    Another fix would be to add an attribute wildcard to the 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:anyAttribute />
    </xs:complexType>
    

    This isn’t an equivalent solution, as it allows an event to have anything for an attribute (which may be undesirable, generally speaking, but perhaps not for code generation), and it doesn’t add an additional type (which is desirable).

    Note that any particles (elements, groups or wildcards) in the base must be repeated in the restriction, else they won’t be allowed in the element. If a restricted attribute is required on the base, it must also be required in the restriction. There are numerous other properties a restriction must fulfill to be a valid derivation or particle. The spec isn’t that readable, but you can usually stumble through it.

    See also: “how to use restrictions and extensions in XSD simultanously“.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.