[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Use complex type many places

From: Scott, Shannon <Shannon.Scott@maine.gov>
Date: Wed, 22 Jul 2009 13:00:43 -0400
Message-ID: <FC23E09CF76C4444B894B2A9F52178DC02A74CF5@SOM-TEAQASMAIL1.som.w2k.state.me.us>
To: <xmlschema-dev@w3.org>
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 
Received on Thursday, 23 July 2009 05:51:00 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.