how to obtain list of enumeration values from an xsd file imported by

R

ryuujin

Hi all,
I have a complex XML schema built by one XSD file importing many
others xsd files. Then, every imported xsd file imports others and so
on.

I'm tryinh to obtain the enumeration of a complex type defined in the
schema. I tried with LINQ, but without success.

If the schema could be one single flatted file, I can obtain what I'm
finding using LINQ to XML.

I tried to convert the multiple schema in a single file... and I was
writing a C# program to accomplish it with a recursive function, but I
couldn't reach any good result but I have only my mind confuse now :)

An example of datas I'm trying to extract from the xsd schema is a
list of countries (but there are many other datas I have to extract):
[...]
<xsd:simpleType name="CountryType">
<xsd:annotation>
<xsd:documentation xml:lang="en">
This is the ISO list of countries and their ISO
abbreviations.
The list is an
enumeration and the key is the abbreviation.
</xsd:documentation>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="AD">
<xsd:annotation>
<xsd:documentation xml:lang="en">Andorra</
xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="AE">
<xsd:annotation>
<xsd:documentation xml:lang="en">United Arab
Emirates</xsd:documentation>
</xsd:annotation>
[...]

The schema containing the country is in a XSD file, imported in a Xsd
file imported then in the master file.

Example:

countries.xsd <-- imported by BaseTypes.xsd <--- imported by xxx.xsd
<--- imported by MAIN.xsd

THANKS!!!

Every answers is graceful... source code, link, examples, ....
 
J

Jeff Johnson

I have a complex XML schema built by one XSD file importing many
others xsd files. Then, every imported xsd file imports others and so
on.

I'm tryinh to obtain the enumeration of a complex type defined in the
schema. I tried with LINQ, but without success.

I know very little about schemas, but I dealt with them programmatically
once a while ago, so here's a thought: Can you build or load a Schema object
from your .xsd and then iterate the properties of the Schema until you find
the enum values?
 
R

ryuujin

I know very little about schemas, but I dealt with them programmatically
once a while ago, so here's a thought: Can you build or load a Schema object
from your .xsd and then iterate the properties of the Schema until you find
the enum values?
I think it is possible but I don't know how I can reach this with
multiple schema. This night I've tried with XmlSchemaSet and
XmlSchemaSet.GlobalTypes property, but I'm not able to use it. I'm
looking for some guide on internet...
....if you have any idea it is very appreciate!!!

Thanks
m.
 
R

ryuujin

I just reached a result using XmlSchemaSet, here is an example on how
to get an enumeration facet from an XSD file:


//we create one xml file for the complex irix xsd
XmlReader xmlReader =
XmlReader.Create([PATH_TO_MASTER_SCHEMA_FILE]);
XmlSchema xmlSchema = XmlSchema.Read(xmlReader, null);
var xmlSchemaSet = new XmlSchemaSet();
xmlSchemaSet.Add(xmlSchema);

xmlSchemaSet.Compile();

foreach (XmlSchema schema in xmlSchemaSet.Schemas()) //we
iterate every schema imported
{
//we are looking for types of
XmlSchemaSimpleTypeRestriction and with the specified name
var simpleType =
schema.SchemaTypes.Values.OfType<XmlSchemaSimpleType>()
.Where(t => t.Content is
XmlSchemaSimpleTypeRestriction).Where(t => t.Name ==
"CountryType").FirstOrDefault();


if (simpleType != null)
{
var restriction = (XmlSchemaSimpleTypeRestriction)
simpleType.Content;
IEnumerable<XmlSchemaEnumerationFacet> enumFacets
= restriction.Facets.OfType<XmlSchemaEnumerationFacet>();
if (enumFacets.Any())
{
Console.WriteLine("" + simpleType.Name);
foreach (XmlSchemaEnumerationFacet facet in
enumFacets)
{
Console.WriteLine(facet.Value);
}
}
}
}

hope you can appreciate this...
....if you have any other suggestions please tell!!!
 
R

ryuujin

Well,
now I have to understand how can I iterate over ComplexType!! :(

If someone can help me... please... it is real indeed appreciate!!!!
 
Top