473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Question about attribute inheritence in XML Schemas using <xsd:extension>

Hi there.

I'm having a problem which I hope is a simple one... Any help would be
appreciated. I think it has something to do with the way attributes are
(or are not) inherited in schemas...

This is the content of my XML Schema (minus the schema tag):

<xsd:complexType name="AType">
<xsd:attribute name="attr1" type="xsd:string" />
<xsd:attribute name="attr2" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="BType">
<xsd:complexContent>
<xsd:extension base="AType">
<xsd:attribute name="attr3" type="xsd:string" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

<xsd:element name="mydoc">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="a" type="AType"/>
<xsd:element name="b" type="BType"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>

In my instance document, I simply want to be able to do the following:

<mydoc xmlns="http://foo.org/foo.xsd">
<a attr1="1" attr2="2"/>
<b attr1="1" attr2="2" attr3="3"/>
</mydoc>

Whenever I try to validate the document, however, I get an error that
attr1 and attr2 are not valid for <b>. But <b> is of BType which
extends AType and attr1 and attr2 are defined for AType. What am I missing?

Thanks in advance,
Sean
Jul 20 '05 #1
2 3068
Sean Bright <se**@seanbright.com> writes:
Hi there.

I'm having a problem which I hope is a simple one... Any help would be
appreciated. I think it has something to do with the way attributes
are (or are not) inherited in schemas...
It may. I suspect it has something to do with the
way namespaces work in XML and in XML Schema.
This is the content of my XML Schema (minus the schema tag):
Can you show us the start-tag of the schema element, too? Only
that will allow us to see whether what is happening below is
what you think is happening. I need to see your namespace
declarations and your targetNamespace attribute.
<xsd:complexType name="AType">
<xsd:attribute name="attr1" type="xsd:string" />
<xsd:attribute name="attr2" type="xsd:string" />
</xsd:complexType>
OK. This declares a complex type named "AType" in the
target namespace.
<xsd:complexType name="BType">
<xsd:complexContent>
<xsd:extension base="AType">
<xsd:attribute name="attr3" type="xsd:string" />
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
OK. This declares a complex type named "BType" in
the target namespace, which in turn extends a complex
type named "AType" in whatever namespace (if any) is
declared as the default namespace in the schema
document.

The local elements will either be qualified names in the target
namespace (if you have one, and if you have specified
elementFormDefault as "qualified"), or unqualified names (names not
associated with any namespace -- some people like to say 'in the
anonymous namespace' and others to say 'not in any namespace')
if you have left elementFormDefault as "unqualified" (the
default).

When I reconstructed your schema just now, I wrote

<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://foo.org/foo.xsd"
xmlns="http://foo.org/foo.xsd"
elementFormDefault="qualified">

and I get no errors from Xerces J when I validate your
sample document.
In my instance document, I simply want to be able to do the following:

<mydoc xmlns="http://foo.org/foo.xsd">
<a attr1="1" attr2="2"/>
<b attr1="1" attr2="2" attr3="3"/>
</mydoc>

Whenever I try to validate the document, however, I get an error that
attr1 and attr2 are not valid for <b>. But <b> is of BType which
extends AType and attr1 and attr2 are defined for AType. What am I
missing?


It's more helpful if you show the error message. My guess is
that one way or another the elements in your document, or the
element declarations in your schema, or the type definitions in
your schema, did not end up in the same namespace.

I hope this helps.

-C. M. Sperberg-McQueen
World Wide Web Consortium
Jul 20 '05 #2
C. M. Sperberg-McQueen wrote:
Can you show us the start-tag of the schema element, too? Only
that will allow us to see whether what is happening below is
what you think is happening. I need to see your namespace
declarations and your targetNamespace attribute.


Aye, there's the rub...

You go on to mention elementFormDefault and attributeFormDefault. The
problem was that in my <xsd:schema> tag I was specifying that the
attributeFormDefault was 'qualified'

Stupid mistake on my part. Combination of my own mistakes and Visual
Studio .NET's intellisense functionality. Apparently Intellisense
(which uses XML Schema to drive it) can not handle the <xsd:extension>
types and I was using the appearance (or lack there of) of attribute
options as the error check, as opposed to running the validator each
time. That'll teach me too be lazy.

Thanks for your feedback, I thought I was going crazy.

Oh, and my targetNamespace was "http://foo.org/foo.xsd" but ultimately
that wasn't the fish I should have been frying.

Thanks,
Sean
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael Bane | last post by:
Am I right in thinking that... 1) in <redefine> I can either extend OR restrict a type but not both? 2) in <redefine> it's not possible to change a type from say <xs:string> to <xs:integer>? ...
0
by: Kent Boogaart | last post by:
Hi, Suppose an XSD as follows: <xsd:complexType name="myType"> <xsd:complexContent> <xsd:extension base="myBaseType"> <xsd:sequence> <xsd:element name="thing" minOccurs="0"...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
0
by: Matt Wood | last post by:
Hi, I have written a Web Service for a customer which expects a SOAP message with Document/Literal encoding, and uses RoutingStyle=SoapServiceRoutingStyle.RequestElement to route the SOAP body...
4
by: martijn | last post by:
H!, Is it possible to get a <tag:id>value</tag:id> value ? When I do this: ----------------------------------------------------- theXML = """<?xml version="1.0"?> <title>The Fascist...
1
by: easy.lin | last post by:
.... <object id="10">door</object> .... I try to write this in clipse XSD editor <element name="object" type="string"> <attribute name="id" type="int"></attribute> </element> but get wrong...
0
by: Rajgodfather | last post by:
I am getting the end couldn't error while validating xml file against xsd. The xml file looks perfect. XML: <event id="1"> <!-- Successful event. --> ...
1
by: =?Utf-8?B?TWFuaXNoIEJhZm5h?= | last post by:
Hi, I am getting following error while validating xml file with schema using ReaderSettings in .NET 2.0 "Line: 0 - Position: 0 - The root element of a W3C XML Schema should be <schemaand its...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.