473,722 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xsd:enumeration inheritance fails

Greetings

I can't seem to inherit enumerated values from a globally defined type
in my XML schema. XmlSchema.Compi le() doesn't like it.

Here's the schema.

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >
<xsd:simpleTy pe name="MYTYPE">
<xsd:restrictio n base="xsd:strin g">
<xsd:enumeratio n value="Option1" />
<xsd:enumeratio n value="Option2" />
<xsd:enumeratio n value="Option3" />
</xsd:restriction >
</xsd:simpleType>
<xsd:element name="Element1" default="Option 1">
<xsd:simpleType >
<xsd:restrictio n base="MYTYPE">
<xsd:enumeratio n value="Option4" />
<xsd:enumeratio n value="Option5" />
<xsd:enumeratio n value="Option6" />
</xsd:restriction >
</xsd:simpleType>
</xsd:element>
</xsd:schema>

Here's the C# source.

const String FILENAME = @"d:\work\schem aTest\schemaTes t2.xsd";

static protected void ValidationCallb ackOne(object sender,
ValidationEvent Args args)
{
Console.WriteLi ne( args.Message );
}

static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ),
null );
schema.Compile( new ValidationEvent Handler(Validat ionCallbackOne) );
}

Here's the output.

The Enumeration constraint failed. An error occurred at
file:///d:/work/schemaTest/schemaTest2.xsd , (13, 10).

Does anyone have any clues? As always, guesses are welcome.
Thanks!
Tony

Nov 12 '05 #1
8 6510
Hi Tony,

When you create new datatypes by restriction, you add constraints to the
possible values of the base type. Your base type "MYTYPE" only allows three
values - "Option1", "Option2", and "Option3". Values "Option4", "Option5",
and "Option6" are not allowed by this datatype. This is why your
restriction is invalid.

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
<ae********@yah oo.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Greetings

I can't seem to inherit enumerated values from a globally defined type
in my XML schema. XmlSchema.Compi le() doesn't like it.

Here's the schema.

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >
<xsd:simpleTy pe name="MYTYPE">
<xsd:restrictio n base="xsd:strin g">
<xsd:enumeratio n value="Option1" />
<xsd:enumeratio n value="Option2" />
<xsd:enumeratio n value="Option3" />
</xsd:restriction >
</xsd:simpleType>
<xsd:element name="Element1" default="Option 1">
<xsd:simpleType >
<xsd:restrictio n base="MYTYPE">
<xsd:enumeratio n value="Option4" />
<xsd:enumeratio n value="Option5" />
<xsd:enumeratio n value="Option6" />
</xsd:restriction >
</xsd:simpleType>
</xsd:element>
</xsd:schema>

Here's the C# source.

const String FILENAME = @"d:\work\schem aTest\schemaTes t2.xsd";

static protected void ValidationCallb ackOne(object sender,
ValidationEvent Args args)
{
Console.WriteLi ne( args.Message );
}

static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ),
null );
schema.Compile( new ValidationEvent Handler(Validat ionCallbackOne) );
}

Here's the output.

The Enumeration constraint failed. An error occurred at
file:///d:/work/schemaTest/schemaTest2.xsd , (13, 10).

Does anyone have any clues? As always, guesses are welcome.
Thanks!
Tony

Nov 12 '05 #2
Thank you for your reply, Stan.

So what you're saying is that my second simpleType can further restrict
MYTYPE, but it cannot extend it using xsd:restrictiio ns, right?

T

Nov 12 '05 #3
Right. If you want to extend it, you need to use xsd:extension

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
<ae********@yah oo.com> wrote in message
news:11******** *************@c 13g2000cwb.goog legroups.com...
Thank you for your reply, Stan.

So what you're saying is that my second simpleType can further restrict
MYTYPE, but it cannot extend it using xsd:restrictiio ns, right?

T

Nov 12 '05 #4
I've got this schema that a big company shipped with one of their
popular products and it is riddled with bugs like this. I should have
known that just because they're a big company doesn't mean that they're
infallible.

Okay, thanks for the info.

T

Nov 12 '05 #5
Would you demonstrate, Stan? I'm confused on the xsd:extension syntax.
I tried this:

<xsd:simpleTy pe name="MYTYPE">
<xsd:restrictio n base="xsd:strin g">
<xsd:enumeratio n value="Option1" />
<xsd:enumeratio n value="Option2" />
<xsd:enumeratio n value="Option3" />
</xsd:restriction >
</xsd:simpleType>

<xsd:element name="Element1" default="Option 1">
<xsd:simpleType >
<xsd:extensio n base="MYTYPE">
<xsd:enumeratio n value="Option4" />
<xsd:enumeratio n value="Option5" />
<xsd:enumeratio n value="Option6" />
</xsd:extension>
</xsd:simpleType>
</xsd:element>

.... but now the XmlSchema object won't even read it in. It tells me
that "extension is invalid in this context".

In case it's unclear, I want element1 to allow the values "Option1",
"Option2", "Option3", "Option4", "Option5", and "Option6".
Thanks
Tony

Nov 12 '05 #6
Hello again.

I changed the subject line to reflect this new, but related problem.

I can see that you can extend (ie: add values to) an xsd:enumeration
with an xsd:union, but XmlSchemaSimple TypeUnion doesn't seem to expose
unioned types that are defined inline.

Sample schema:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" >

<xsd:simpleTy pe name="MYTYPE">
<xsd:restrictio n base="xsd:strin g">
<xsd:enumeratio n value="Option1" />
</xsd:restriction >
</xsd:simpleType>

<xsd:element name="Element1" default="Option 1">
<xsd:simpleType >
<xsd:union memberTypes="MY TYPE">
<xsd:simpleType >
<xsd:restrictio n base="xsd:strin g">
<xsd:enumeratio n value="Option2" />
</xsd:restriction >
</xsd:simpleType>
</xsd:union>
</xsd:simpleType>
</xsd:element>

</xsd:schema>

The following C# code only prints the name of the first member type in
the union (ie: the one defined globally). The second member type,
which is declared inline and nameless (the XmlSchema class requires it
to be nameless), doesn't seem to be accessible. Specifically, I want
to get at the facets of the inline type.

const String FILENAME = @"schemaTest3.x sd";

static protected void ValidationCallb ackOne(object sender,
ValidationEvent Args args)
{
Console.WriteLi ne( args.Message.Su bstring(0,34) );
}

static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ), null
);
schema.Compile( new ValidationEvent Handler(Validat ionCallbackOne) );

XmlSchemaSimple TypeUnion u =
(XmlSchemaSimpl eTypeUnion)((Xm lSchemaSimpleTy pe)((XmlSchemaE lement)schema.I tems[1]).SchemaType).C ontent;

foreach( XmlQualifiedNam e entry in u.MemberTypes )
{
Console.WriteLi ne( entry.Name );
}

}

I tried giving the inline type a name, then using that name in the
memberTypes attribute of the xsd:union element, but the XmlSchema class
didn't like that. Yes, I know I could define the inline type globally,
but I don't have that much control over the schema.

Surely there must be a way to access this inline type. Can anyone help
me? As always, all suggestions are welcome.

Thanks
Tony

Nov 12 '05 #7
Argh! Figured it out.

Where MemberTypes contains the names of the types in the memberTypes
list, BaseTypes contains a list of the types defined inline.
<sigh>

Disregard.

Thanks
Tony

Nov 12 '05 #8
Hi Tony,

Sorry for the late reply - I just got back from the holiday break. Glad you
figured it out.

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
<ae********@yah oo.com> wrote in message
news:11******** **************@ c13g2000cwb.goo glegroups.com.. .
Argh! Figured it out.

Where MemberTypes contains the names of the types in the memberTypes
list, BaseTypes contains a list of the types defined inline.
<sigh>

Disregard.

Thanks
Tony

Nov 12 '05 #9

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

Similar topics

1
12631
by: Justin Wright | last post by:
I know that I can set up an enumeration as follows ( just typed in quick so may have syntax errors ): <xsd:simpleType name="colors"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="red"/> <xsd:enumeration value="yellow"/> <xsd:enumeration value="blue"/> </xsd:simpleType>
0
1634
by: Fender Mussel | last post by:
Hi all, Is it possible to check the content of a mixed type? I would like to define an enumeration for it. The following example works syntactically, but XMLSpy does no checks on the content at all: <xsd:simpleType name="my_enum_type"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="enum1"/> <xsd:enumeration value="enum2"/>
0
1332
by: Codex Twin | last post by:
hello group: The following is a fragment from a schema which defines the EWethnicCategoryStructure type. As you can see, its type is defined by the SimpleType enumeration EWethnicCategoryType. EWethnicCategoryType is defined as a union with the CommonEthnicCategoryType SimpleType enumeration. Now when I use the XSD tool to create a C# class of this schema, the resulting code does not include the SelectedEthnicCategory enumeration.
1
3666
by: Sergey Poberezovskiy | last post by:
Hi, I have a simple enumeration in my schema: <xs:element name="el_1"> <xs:simpleType> <xs:restiction base="xs:string"> <xs:enumeration value="value and space 1"/> <xs:enumeration value="value2 with spaces"/> ...
2
2285
by: aevans1108 | last post by:
Greetings Please give me a push in the right direction if this the wrong place to ask this question. Why is it that I can get the count of facets for an element restriction if the corresponding simpleType is declared inline, but I can't get it if the simpleType is globally defined? Given this schema:
8
1566
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
0
1056
by: JamesSmithMz | last post by:
Hi, I'm new in XSD. So I like to enforce the creating of the XML-file. The XML-Strukture would be linke this: <types> <type name="x"/> <type name="y"/> <type name="z"/> </types> <elements>
3
2543
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
0
500
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
0
8861
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
9236
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
9154
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
8051
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...
1
6681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2601
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.