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

  • SEARCH
  • Home
  • 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 887267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:12:16+00:00 2026-05-15T13:12:16+00:00

Taking the W3C vehicle XSD as an example: <schema xmlns=http://www.w3.org/2001/XMLSchema targetNamespace=http://cars.example.com/schema xmlns:target=http://cars.example.com/schema> <complexType name=Vehicle

  • 0

Taking the W3C vehicle XSD as an example:

<schema xmlns="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://cars.example.com/schema"
           xmlns:target="http://cars.example.com/schema">

  <complexType name="Vehicle" abstract="true"/>

  <complexType name="Car">
    <complexContent>
      <extension base="target:Vehicle"/>
      ...
    </complexContent>
  </complexType>

  <complexType name="Plane">
    <complexContent>
      <extension base="target:Vehicle"/>
      <sequence>
        <element name="wingspan" type="integer"/>
      </sequence>
    </complexContent>
  </complexType>      
</schema>

, and the following definition of ‘meansOfTravel’:

<complexType name="MeansOfTravel">
  <complexContent>
    <sequence>        
      <element name="transport" type="target:Vehicle"/>        
    </sequence>
  </complexContent>
</complexType>

<element name="meansOfTravel" type="target:MeansOfTravel"/>

With this definition you need to specify the type of your instance using xsi:type, like this:

<meansOfTravel>
  <transport xsi:type="Plane">
     <wingspan>3</wingspan>
  </transport>
</meansOfTravel>

I would just like to acheive a ‘name of type’ – ‘name of element’ mapping so that this could be replaced with just

<meansOfTravel>
  <plane>
    <wingspan>3</wingspan>
  </plane>
</meansOfTravel>

The only way I could do this until now is by making it explicit:

<complexType name="MeansOfTravel">
  <sequence>        
    <choice>
      <element name="plane" type="target:Plane"/>
      <element name="car" type="target:Car"/>         
    </choice>
  </sequence>
</complexType>

<element name="meansOfTravel" type="target:MeansOfTravel"/>

But this means that I have to list all possible sub-types in the ‘MeansOfTravel’ complex type. Is there no way of making the XML parser assume that you mean a ‘Plane’ if you call the element ‘plane’? Or do I have to make the choice explicit? I would just like to keep my design DRY – if you have any other suggestions (like groups or so) – i am all ears.

  • 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-15T13:12:17+00:00Added an answer on May 15, 2026 at 1:12 pm

    There is a common design pattern around this, you can use sub-types (as you are already doing), and elements in a substitution group. Elements in the substitution group have to be of a sub-type of the element they are substituted for.

    Unfortuntaly, substitution group elements need to be defined as global elements. So you would have this:

    <complexType name="MeansOfTravel">
      <complexContent>
        <sequence>        
          <element ref="transport"/>
        </sequence>
      </complexContent>
    </complexType>
    
    <element name="transport" type="target:Vehicle"/>
    <element name="plane" type="target:Plane" substitutionGroup="target:transport"/>
    

    Then, in your XML document you can use:

    <meansOfTravel>
        <plane>...</plane>
    </meansOfTravel>
    

    More info on substitution groups here. And no, unfortunately the parser cannot guess this, so you still have to list the elements 🙁 There is one advantage over a choice though: the schema can be extended externally, by importing it, without modifying it. The choice could not be extended.

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

Sidebar

Related Questions

Taking this simplifed example of my XML: <?xml version=1.0?> <message xmlns=http://www.mydomain.com/MyDataFeed xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.mydomain.com/MyDataFeed https://secure.mydomain/MyDataFeed/myDataFeed.xsd
<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01//EN http://www.w3.org/TR/html4/strict.dtd> <html> <head> <style> table {border: 1px solid
Taking this article on classes and structs as an example: http://msdn.microsoft.com/en-us/library/ms173109.aspx namespace ProgrammingGuide {
I have the following code: <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd> <html
I have the following simple XSL style sheet: <?xml version=1.0 encoding=windows-1252?> <xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns=http://www.w3.org/1999/xhtml
Taking this file as an example, I'm trying to read the data in a
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
Why Textarea and textfield not taking font-family and font-size from body? See live example
http://www.webdevout.net/test?013&raw Shrink the window in IE6 / 7 to see what I'm talking about.
Taking this below example : 'user_stats': {'Blog': '1', 'Discussions': '2', 'Followers': '21', 'Following': '21',

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.