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

RE: XML-SCHEMA Q: Adding an xsd:attribute to an xsd:element

  • To: "'Richard Rowell'" <richard@b...>, xml-dev@l...
  • Subject: RE: XML-SCHEMA Q: Adding an xsd:attribute to an xsd:element
  • From: "Leach, Phillip (Contractor)" <leacp1@b...>
  • Date: Thu, 15 May 2003 17:07:13 +0100

xsd attribute
Try the following:

<?xml version = "1.0" encoding = "UTF-8"?>
<!--Generated by Turbo XML 2.4.0.100. Conforms to w3c
http://www.w3.org/2001/XMLSchema-->
<xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
	 elementFormDefault = "qualified">
	<xsd:element name = "box">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name = "size">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name =
"width">
	
<xsd:complexType>
	
<xsd:simpleContent>
	
<xsd:extension base = "xsd:integer">
	
<xsd:attribute name = "units" type = "xsd:string"/>
	
</xsd:extension>
	
</xsd:simpleContent>
	
</xsd:complexType>
							</xsd:element>
							<xsd:element name =
"height">
	
<xsd:complexType>
	
<xsd:simpleContent>
	
<xsd:extension base = "xsd:integer">
	
<xsd:attribute name = "units" type = "xsd:string"/>
	
</xsd:extension>
	
</xsd:simpleContent>
	
</xsd:complexType>
							</xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>

--

<?xml version = "1.0" encoding = "UTF-8"?>
<box xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation = "test.xsd">
 	<size>  
		 <width units = "cm">50</width>  
		 <height units = "m">1</height>
	 </size>
</box>


Phil.
-----Original Message-----
From: Richard Rowell [mailto:richard@b...]
Sent: 15 May 2003 16:47
To: xml-dev@l...
Subject:  XML-SCHEMA Q: Adding an xsd:attribute to an
xsd:element


I'm sure the answer is painfully obvious, but I cant figure out how to
add an attribute to an element.  I want a structure like this:

<box>
 <size>
   <width units='cm'>50</width>
   <height units='m'>1</width>
 </size>
</box>

AFAICT I can only attach attributes to complex types in XMLSchema, but
width and height are not complex types (are they?).  I know how to
attach the "units" attribute to the size element, but I don't want it
there.  This is what I have tried:

<xsd:element name="size">
     <xsd:complexType>
      <xsd:all>
       <xsd:element name="width" type="xsd:integer" minOccurs='1'
maxOccurs='1'>
        <xsd:attribute name='units' type="xsd:string"/>
       </xsd:element>
       <xsd:element name="height" type="xsd:integer" minOccurs='1'
maxOccurs='1'/>
      </xsd:all>
     </xsd:complexType>
    </xsd:element>

Xerces rejects this though:
** Schema error: src-element.0: the content of an element information
item must match (annotation?, (simpleType | complexType)?, (unique | key
| keyref)*). **
LINE: 1
PUBLIC_ID: null
SYSTEM_ID: 

-- 
Richard Rowell <richard@b...>

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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-2013 All Rights Reserved.