W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2003

RE: Help! Can't XML Schema do this?

From: Norris Merritt <norris.merritt@peregrine.com>
Date: Mon, 24 Feb 2003 18:00:09 -0800
Message-ID: <D54BF26DB5A7D511B36B00508B9596A40371FBBD@sdgcaexch2.peregrine.com>
To: "'bibhaker.saran@txu.com.au'" <bibhaker.saran@txu.com.au>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>

I'm sorry, I don't understand. Do you suggest I should use the same type and
same element name for the child elements as for the parent element, and
allow either attribute to appear, i.e.:

<description type="array">
  <description type="string">DESCRIPTION LINE 1</description>
  <description type="string">DESCRIPTION LINE 2</description>


<comment type="array">
  <comment type="string">ADDRESS LINE 1</comment>
  <comment type="string">ADDRESS LINE 2</comment>

Given the XML examples above, I want both "description" and "comment" to be
instances of the SAME complexType,(lets call it "stringArray") defined in
such a way that the contained element names representing the array entries
are NOT used in the definition of the complex type, so that I don't have
hundreds of essentially identical type definitions. Then, if I wanted to
define a larger document called "foo" consisting of the two "stringArrays"
just described, I would do so like this:

<xs:element name="foo" >
      <xs:element  name="description" type="stringArray" />
      <xs:element  name="comment"     type="stringArray" />

If the solution involves using the same element name for the contained
elements as for the parent element, that's fine with me (as a matter of
fact, the application currently does this) but I thought  that was invalid
with XML schema and that I would have to change the XML emitted by the
What would the XML Schema look like to describe such a "stringArray" type?
Can it be defined in an abstract way so that the element names "description"
and "comment" do NOT appear in the .xsd definition for the complexType
"stringArray", but only in the definition of a larger element, such as "foo"
given immediately above?
My objective is to be able to describe large documents containing
differently named instances of structures like the ones above, using a
single complexType, called something such as "stringArray".
What I want to avoid is to have a complexType definition for a "stringArray"
which contains "comment" elements and another almost identical one for a
stringArray containing "description" elements.

XML Schema doesn't require me to name the containING element when I define a
new type, which is good, but it does seem to require me to name any
containED elements, which is frustrating.

-----Original Message-----
From: bibhaker.saran@txu.com.au [mailto:bibhaker.saran@txu.com.au]
Sent: Monday, February 24, 2003 4:31 PM
To: Norris Merritt
Cc: xmlschema-dev@w3.org
Subject: Re: Help! Can't XML Schema do this?

Yes, add an attribute name of xsd:string type to your complexType "array".
Bibhakar Saran
B2B Technical Architect
TXU IT Architecture & Planning
Level 15 452 Flinders St, Melbourne
Phone : (+61 3) 9229 6153
Mobile: 0411 203036
Email: bibhaker.saran@txu.com.au


                      Norris Merritt

                      <norris.merritt@per         To:
"'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>             
                      egrine.com>                 cc:

                      Sent by:                    Subject: Help! Can't XML
Schema do this?                             




                      25/02/2003 10:30 AM



I'm having trouble trying to create one small set of reusable .xsd
definitions that I can use to describe a lot of existing xml fragments that
follow the simple pattern shown below, without having to hard-code any
element names.  If I have to define a complex type for each such XML
fragment, and hard-code the element names for the contained child elements,
it forces me to replicate the same schema definitions many many times, even
though all the XML fragments have the exact same structure and follow the
same rules. They just have different element names. For example:

<Array1 mytype="array">
  <Array1Elem mytype="string">foo</Array1Elem>
  <Array1Elem mytype="string">bar</Array1Elem>

I have many occurrences of XML fragments like the one shown above. It is
infeasible to duplicate the schema code for each possible element name.  So
I just want to define some complex types where the actual element names can
vary.  All of the contained elements always have the same name and type.

Can this be done using abstract elements? Substitution groups? Some other
feature? Not at all?

This email and any files transmitted with it may be confidential and are
solely for the use of the individual or entity to whom they are addressed.
confidentiality is not waived or lost because this email has been sent to
you by
mistake. This email may contain personal information of individuals, and be 
subject to Commonwealth and/or State privacy laws in Australia. This email
is also subject to copyright. If you are not the intended recipient, you
must not
 read, print, store, copy, forward  or use this email for any reason, in
 with privacy and copyright laws. If you have received this email in error,
notify the sender by return email, and delete this email from your inbox.
Received on Monday, 24 February 2003 21:18:27 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:55:59 UTC