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 1553
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: 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: 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: Stefano G. |
last post by:
I have a WSDL containing this enumeration type
<xsd:simpleType name="item_type_enum">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="VCD"/>
<xsd:enumeration value="SVCD"/>...
|
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: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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,...
|
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...
| |