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