trying to get facets of globally defined xsd:simpleType

A

aevans1108

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:

<?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="xsd:string">
<xsd:enumeration value="Option1" />
<xsd:enumeration value="Option2" />
<xsd:enumeration value="Option3" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Element2" type="MYTYPE" default="Option1">
</xsd:element>
</xsd:schema>

This code:

class Class1
{
const String FILENAME = @"d:\work\schemaTest\schemaTest.xsd";

static void Main()
{
XmlSchema schema = XmlSchema.Read( new XmlTextReader( FILENAME ),
null );
foreach( XmlSchemaObject entry in schema.Items )
{
if( entry is XmlSchemaElement )
{

Console.WriteLine(((XmlSchemaSimpleTypeRestriction)((XmlSchemaSimpleType)(((XmlSchemaElement)entry).SchemaType)).Content).Facets.Count);
}
}
}
}

breaks on the second iteration through the for loop.

I guess my real question is: What's the easiest way to get at the
facets collection of a globally defined type as I'm iterating over
elements in the schema?

I'll appreciate any replies, including guesses.

Thanks in advance for your time.
Tony

PS> I wish google would let me format code prettier.
 
A

aevans1108

Excuse me -- I should say that it throws an exception on the last
iteration through the loop.

Yes, I know I could build my own type cache and search it by name every
time I encounter the type in the rest of the schema, but there's got to
be a better way than that.

Thanks
Tony
 
A

aevans1108

Nevermind - I'll just dereference the SchemaTypes property by name.

It's unfortunate that the XmlSchema object doesn't automatically
amalgamate the base types with the derived types so the above code
fragment would just work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top