Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: Use complex type many places

From: "Michael Kay" <mike@--------.--->
To: "'Scott, Shannon'" <Shannon.Scott@-----.--->, <xmlschema-dev@--.--->
Date: 7/23/2009 8:46:00 AM
Although the lexical space of integer is a subset of the lexical space of
string, integer is not derived by string by restriction. This decision has
been controversial, but there are those who feel that declaring something as
a string conveys something about the intended use of the type which is not
true of say integers, dates, or booleans. So once you've declared that your
type contains strings, you can't change you mind and say that it contains
integers.
 
In principle the right thing to do would probably be to declare your type's
simple content as being the base type of string and integer, which is
anySimpleType, making your type abstract so that it has to be specialized as
string or integer in a concrete type derived by restriction. But using
anySimpleType can be problematic and the rules are a little unclear, so I'm
not sure I would advise it.
 
With XSD 1.1 you can declare a default attribute group that applies to all
types, and you can then make this default attribute group allow xml:space
and any other chosen attributes.
 
With XSD 1.0 I think I would probably make all relevant types include such
an attribute explicitly.
 
Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


  _____  

From: xmlschema-dev-request@w... [mailto:xmlschema-dev-request@w...] On
Behalf Of Scott, Shannon
Sent: 22 July 2009 18:01
To: xmlschema-dev@w...
Subject: Use complex type many places



Hello,
I have a simple XML file:
<?xml version="1.0" standalone="yes"?>
<mytext xml:space="preserve">the text</mytext>

I have a complex type that manages the xml:space attribute. The xsd looks
like this:
<?xml version="1.0"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
schemaLocation="xml.xsd"/>
<xs:element name="mytext">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute ref="xml:space"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>

Everything works fine. 

Now I want to add a new line to my XML so it looks like this:
<?xml version="1.0" standalone="yes"?>
<mytext xml:space="preserve">some text</mytext>
<mynumber xml:space="preserve">5555</mynumber>

I know that complex types can be named and reused, but I have not been able
to figure out the correct syntax. I am hoping not to repeat the complex type
under each element in my xsd ( because any element could have the xml:space
attribute ).
When I put the complex type under the <mynumber> element in the xsd, it
breaks because the <mynumber> element is of type decimal.

How can I reuse the complex type?
How do I use the complex type in the mynumber element and still maintain the
business rule saying that the mynumber tag should always contain decimals?

Any help is greatly appreciated.
Thank you.
Shannon 




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent