Introduction

This article shows how to use a Schema Object Model(SOM) navigator as an arbitrary schema. This is useful when you have a schema and want to generate your own mapping or want to build a custom XML generator or XSD based code generator.

Points of Interest

There's a lot of type checking and casting. That's inherent in the data model used in the SOM. It's not a strongly typed data structure. So you have to check, cast, then use. It would be an interesting exercise to generate a strongly typed XSD model, but I'll leave that for another article.

I need to parse this schema and store the complex element in CEarray() with its position in CE-levelarray(),the simple element in SEarray() and its position in SElevel_array(), and the keys in keyarray(), its level in keylevel()Thanks in advance

Many thanks, This article has allowed me break into the belly of the SOM monster in a way that none other that I found could do.

I suspect if I get the time to apply it as I plan to, my finished product will bear little resemblence to this, but every journey begins with a first step, until I found this article, I was unable to take that first step.

I threw an EU Entry Summary Declaration (IE315) at it to see how it would cope. It is only picking out some elements, but I suspect that down to that fact that I must have missed something translating it to C++/CLI.

After you cast the XmlSchemaObject, you can access the Annotation property, which contains an Items property. Check for each item that is of the type XmlSchemaDocumentation. The Markup (string array) property will contain the documentation nodes.

I noticed you didn't include <xs:all>. I could be wrong but if I were to include that, I would just need to add : private static void ProcessAll(XmlSchemaAll all) { Console.WriteLine("All"); ProcessItemCollection(all.Items); }

Also, in my XSD document there a couple of nested <xs:group>'s. So it's causing it go into an infinite loop. Here is a sample xsd:

Once it reaches the element "Role" it goes into the ref "RoleNodes". And inside on this group, RoleNodes, there is a nested ref to itself again after the element "ActiveItems". So, it is looping infinitely. And the element "Active Items" keeps being written out on the Console.

<b>What can I do to avoid this? Is there a way to detect nested group ref's and find a work-around for it? </b>

I use all the code-generators on a regular basis for my day job. I finally found on that could generate a strongly typed data model from the xsd.xsd (schema schema). So I will be posting another article on that soon, I'll link forward when it's done