473,652 Members | 2,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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:complexTyp e name="AType">
<xsd:attribut e name="attr1" type="xsd:strin g" />
<xsd:attribut e name="attr2" type="xsd:strin g" />
</xsd:complexType >

<xsd:complexTyp e name="BType">
<xsd:complexCon tent>
<xsd:extensio n base="AType">
<xsd:attribut e name="attr3" type="xsd:strin g" />
</xsd:extension>
</xsd:complexCont ent>
</xsd:complexType >

<xsd:element name="mydoc">
<xsd:complexTyp e>
<xsd:choice maxOccurs="unbo unded">
<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 3094
Sean Bright <se**@seanbrigh t.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:complexTyp e name="AType">
<xsd:attribut e name="attr1" type="xsd:strin g" />
<xsd:attribut e name="attr2" type="xsd:strin g" />
</xsd:complexType >
OK. This declares a complex type named "AType" in the
target namespace.
<xsd:complexTyp e name="BType">
<xsd:complexCon tent>
<xsd:extensio n base="AType">
<xsd:attribut e name="attr3" type="xsd:strin g" />
</xsd:extension>
</xsd:complexCont ent>
</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
elementFormDefa ult 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 elementFormDefa ult as "unqualifie d" (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"
elementFormDefa ult="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 elementFormDefa ult and attributeFormDe fault. The
problem was that in my <xsd:schema> tag I was specifying that the
attributeFormDe fault 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:extensio n>
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
1683
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>? 3) if I have schema1.xsd with <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
0
1155
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" maxOccurs="unbounded">
16
4902
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 Microsoft must be installed on their servers. Now german Umlaute (ä, ü, ö) and quotes are returned incorrectly in SOAP fault responses. This can be easily verified: Implement the following in a web service method (just raises a SOAPException with a...
0
4352
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 message to my Web Method. The Web Method expects a string as its parameter and then feeds that string to an XML deserializer which maps the XML elements contained within the string to my custom objects, then performs an insert/update on an SQL...
4
1890
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 Menace</title> """ import xml.dom.minidom as dom
1
1644
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 message....
0
1569
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. --> <AffectedBillingComponentsRequest
1
10370
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 namespace should be 'http://www.w3.org/2001/XMLSchema'." First few lines of xsd file are as follows: <?xml version="1.0" encoding="utf-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.keaneaustralia.com/Nts"...
0
8367
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8811
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8703
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8467
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7302
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5619
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4145
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2703
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.