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" <google.user@mail.com> wrote in message
news:1147283383.630932.224530@j33g2000cwa.googlegr oups.com...[color=blue]
> 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
>[/color]