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">
<xsd:simpleType name="MYTYPE">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Option1" />
<xsd:enumeration value="Option2" />
<xsd:enumeration value="Option3" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Element1" default="Option1">
<xsd:simpleType>
<xsd:restriction base="MYTYPE">
<xsd:enumeration value="Option4" />
<xsd:enumeration value="Option5" />
<xsd:enumeration value="Option6" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
Here's the C# source.
const String FILENAME = @"d:\work\schemaTest\schemaTest2.xsd";
static protected void ValidationCallbackOne(object sender,
ValidationEventArgs args)
{
Console.WriteLine( args.Message );
}
static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ),
null );
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
}
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 8 6480
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********@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com... 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"> <xsd:simpleType name="MYTYPE"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Option1" /> <xsd:enumeration value="Option2" /> <xsd:enumeration value="Option3" /> </xsd:restriction> </xsd:simpleType> <xsd:element name="Element1" default="Option1"> <xsd:simpleType> <xsd:restriction base="MYTYPE"> <xsd:enumeration value="Option4" /> <xsd:enumeration value="Option5" /> <xsd:enumeration value="Option6" /> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:schema>
Here's the C# source.
const String FILENAME = @"d:\work\schemaTest\schemaTest2.xsd";
static protected void ValidationCallbackOne(object sender, ValidationEventArgs args) { Console.WriteLine( args.Message ); }
static void Main() { XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ), null ); schema.Compile(new ValidationEventHandler(ValidationCallbackOne)); }
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
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:restrictiions, right?
T
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********@yahoo.com> wrote in message
news:11*********************@c13g2000cwb.googlegro ups.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:restrictiions, right?
T
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
Would you demonstrate, Stan? I'm confused on the xsd:extension syntax.
I tried this:
<xsd:simpleType name="MYTYPE">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Option1" />
<xsd:enumeration value="Option2" />
<xsd:enumeration value="Option3" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Element1" default="Option1">
<xsd:simpleType>
<xsd:extension base="MYTYPE">
<xsd:enumeration value="Option4" />
<xsd:enumeration value="Option5" />
<xsd:enumeration 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
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 XmlSchemaSimpleTypeUnion 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"
elementFormDefault="qualified">
<xsd:simpleType name="MYTYPE">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Option1" />
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="Element1" default="Option1">
<xsd:simpleType>
<xsd:union memberTypes="MYTYPE">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration 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.xsd";
static protected void ValidationCallbackOne(object sender,
ValidationEventArgs args)
{
Console.WriteLine( args.Message.Substring(0,34) );
}
static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ), null
);
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
XmlSchemaSimpleTypeUnion u =
(XmlSchemaSimpleTypeUnion)((XmlSchemaSimpleType)(( XmlSchemaElement)schema.Items[1]).SchemaType).Content;
foreach( XmlQualifiedName entry in u.MemberTypes )
{
Console.WriteLine( 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
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
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********@yahoo.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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....
|
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...
|
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...
|
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"...
|
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>
|
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">...
|
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>
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |