473,486 Members | 2,383 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Get valid values for an element from its schema

GU
How can one get a list of enumeration values for a given element in an
XML schema? I have been looking at the Schema Object Model, but I'm
making very little headway. Can anyone give me a nudge in the right
direction?

Specifically, I am using Actions Pane to assist in creating a WordML
document. For elements with enumerated values, I want to provide the
user with the list of valid values from the schema. For example, if I
have an element defined like this:

<xs:element name="distribtype">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

I want to show the user a ComboBox containing only those values.
Warning, confused rambling ahead:

I think I might be able to figure out how to use XmlSchema.SchemaTypes
to get part of the way, but only if the schema uses named types (which
it doesn't). It looks like I may have to dig through the Items
collection of the XmlSchema, although I haven't found any way to look
for a specific element yet. Even then, I'm still not sure how to dig
all the way down to the facets and find out what the possible values
are.

Thanks,

Jon

May 10 '06 #1
1 2040
Hi Jon,

If you want to get a list of expected elements (for example, in a sequence
or a choice), you can use XmlSchemaValidator.GetExpectedParticles method
(http://msdn2.microsoft.com/en-us/lib...particles.aspx)

If you want to get enumeration values for a given element/attribute, you can
use XmlSchemaEnumerationFacet class
(http://msdn2.microsoft.com/en-us/lib...ionfacet.aspx).

The example below shows how to use XmlSchemaEnumerationFacet to retrieve
enumeration values. "st" here is the (simple) type of your
element/attribute.

if (st.Content is XmlSchemaSimpleTypeRestriction)

{

XmlSchemaSimpleTypeRestriction xsstr = st.Content as
XmlSchemaSimpleTypeRestriction;

foreach (XmlSchemaFacet xsf in xsstr.Facets)

{

if (xsf is XmlSchemaEnumerationFacet)

{

// handle xsf.Value

}

}

}
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"GU" <go*********@mail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
How can one get a list of enumeration values for a given element in an
XML schema? I have been looking at the Schema Object Model, but I'm
making very little headway. Can anyone give me a nudge in the right
direction?

Specifically, I am using Actions Pane to assist in creating a WordML
document. For elements with enumerated values, I want to provide the
user with the list of valid values from the schema. For example, if I
have an element defined like this:

<xs:element name="distribtype">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="A"/>
<xs:enumeration value="B"/>
<xs:enumeration value="C"/>
<xs:enumeration value="D"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

I want to show the user a ComboBox containing only those values.
Warning, confused rambling ahead:

I think I might be able to figure out how to use XmlSchema.SchemaTypes
to get part of the way, but only if the schema uses named types (which
it doesn't). It looks like I may have to dig through the Items
collection of the XmlSchema, although I haven't found any way to look
for a specific element yet. Even then, I'm still not sure how to dig
all the way down to the facets and find out what the possible values
are.

Thanks,

Jon

May 12 '06 #2

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

Similar topics

0
1250
by: kelvSYC | last post by:
Is it possible in XML Schema to have the values of one attribute be only the values of another attribute in some other element? Let me explain: Suppose you have something like <root> <a...
1
2169
by: wooks | last post by:
The schema below describes an interface to a form where the appInterface type is an extension of an abstract type called interface and it contains an appFrame element that is an extension of an...
2
3941
by: Bill Cohagan | last post by:
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications. I'm performing the validation via an xml document load() using a...
2
6880
by: joewhitehair | last post by:
Using the XSD.exe tool, I created a number of classes from my XSD file. When I generate the WSDL for my web service, the schema does not have the proper Occurance constraints for the attributes. In...
2
9485
by: Jeremy Chapman | last post by:
Populating a typed dataset from xml document: I created an xml schema (attached below), generated a typed dataset from it, and then programatically I tried to populate the typed dataset by...
0
1781
by: DotDidIt | last post by:
Hi Everybody! I developed a Web service with IBM RAD v 6.0.1. After creating the WSDL file i have tried to develop a .Net client. But by using wsdl.exe (1.1.4322) to create a .net c# proxy i...
1
1844
by: merdaf | last post by:
Hallo all, I am looking for a funcion in the .Net framework that returns a list of all the valid elements, for a specific element, accrording to the xml schema restrictions. I will try to be...
7
9846
by: Christian Hackl | last post by:
Hi everyone, I've got a question about what makes the "img" element's width/height attributes valid HTML or XHTML. First of all, this is a rather theoretical question, but digging through the...
1
4012
by: jan.geek | last post by:
Hi all, When reading the following ugly but valid (according to w3c XSV) xsd into a DataSet I get "Duplicated declaration PossiblesValue" error. Can anyone tell me why? This is a small part...
0
7100
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
6964
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...
0
7126
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
7175
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...
1
6842
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
5434
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,...
0
4559
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...
0
3070
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...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.