RE: Attributes and Default Namespaces

Actually, I  Figured it out.  I was rustier than I thought.  I was creating attributes outside the element when what I should have been doing is creating types and using those for the attributes instead. 

-----Original Message-----
From: Neil Beddoe 
Sent: 11 November 2010 14:48
To: 'xmlschema-dev@w3.org'
Subject: Attributes and Default Namespaces

Hi,

I'm having trouble understanding why validation of the following xml fails against my schema:

<?xml version="1.0" encoding="UTF-8"?>
<Results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://raid.raidllp.com" xsi:schemaLocation="http://raid.raidllp.com file:///C:/Development/XML/RAIDTable.xsd">
	<Row>
		<Field FieldID="1234" FieldType="Ticker" Name="Ticker">CARLB DC Equity</Field>
		<Field FieldID="1234" FieldType="String" Name="Name">CARLSBERG AS-B</Field>
	</Row>
</Results>

The schema is below.  Validation fails because FieldID is not a valid attribute.  If I change xmlns="http://raid.raidllp.com"  to xmlns:raid="http://raid.raidllp.com" and qualify all the xml (<raid:Results, <raid:field , raid:FieldID etc) then the xml will validate. 

I don't understand how the attributes need a namespace prefix when I do xmlns="http://... but the elements themselves don't.

My XML is very rusty so any help anyone can give me would be gratefully received.

Neil

Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:rd="http://raid.raidllp.com" targetNamespace="http://raid.raidllp.com">
	<xs:attribute name="RowType">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Stock"/>
				<xs:enumeration value="Pattern"/>
				<xs:enumeration value="OtherThing"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:attribute>
	<xs:attribute name="FieldID" type="xs:string"/>
	<xs:attribute name="FieldType">
		<xs:simpleType>
			<xs:restriction base="xs:string">
				<xs:enumeration value="Ticker"/>
				<xs:enumeration value="Price"/>
				<xs:enumeration value="String"/>
				<xs:enumeration value="BrokerOpinion"/>
				<xs:enumeration value="PctChange"/>
				<xs:enumeration value="Pct"/>
			</xs:restriction>
		</xs:simpleType>
	</xs:attribute>
	<xs:attribute name="Name"/>
	<xs:element name="Results">
		<xs:annotation>
			<xs:documentation>Comment describing your root element</xs:documentation>
		</xs:annotation>
	</xs:element>
	<xs:element name="Row">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="rd:Field" minOccurs="1" maxOccurs="unbounded"/>
			</xs:sequence>
			<xs:attribute ref="rd:RowType"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="Field">
		<xs:complexType mixed="true">
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute ref="rd:FieldID" use="required"/>
					<xs:attribute ref="rd:FieldType"/>
					<xs:attribute ref="rd:Name"/>
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
</xs:schema>


..

This message is intended only for the use of the person(s) to whom it is addressed. It may contain information which is privileged and confidential. Accordingly any unauthorised use is strictly prohibited. If you are not the intended recipient, please contact the sender as soon as possible.

It is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction, unless specifically agreed otherwise. All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any opinions or advice contained in this Internet email are subject to the terms and conditions expressed in any applicable governing Marble Bar Asset Management LLP's  terms and conditions of business or client agreement letter. Any comments or statements made herein do not necessarily reflect those of Marble Bar Asset Management LLP.

Marble Bar Asset Management LLP is regulated and authorised by the FSA.

Received on Thursday, 11 November 2010 22:13:02 UTC