Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
233
Extracting Schemas for Nested Classes
In listing C.3 the two classes: garage and garageCar were listed
sequentially, which does not reflect the relationship the types of the
garageCar and garage element had in the schema in listing C.2 where the
complexType of the car element was declared inline of the garage element. A
nested class definition as shown in listing C.10 would be a closer match to the
semantics of the schema.
10 Listing C.10 Nested definition
of the Garage can garageCar classes
If we built an assembly class definition above and extracted a schema from
that assembly, we would get a schema with the same validation semantics as the
schema in listing C.2, i.e. without a top-level element for the garageCar
class.
11 Listing C.11 Schema extracted
from an assembly with nested classes
(annotation) <#1 Nested classes only produce an element for the
outer class. >
Extracting Types using XmlTypeAttribute
When the XSD tool analyzes an assembly to generate a schema, it inspects
every class for the XmlTypeAttribute. By default each class in the assembly
produces a complexType in the schema. The XmlTypeAttribute’s TypeName can
specify an alternate name for complexType. If the IncludeInSchema property is
set to false the tool will exclude the class from the schema.
Extracting Specific Classes from an Assembly
If we need to generate a schema only for certain classes in an assembly, we
can supply a /t command-line option for each class we want to include in the
schema. If we only need an element for the garageCar class in the garage.dll
assembly from section C.5.1 we would invoke xsd.exe as follows:
xsd.exe garage.dll /t:garageCar
Now the output schema only contains a garageCar element and its type
description:
The parameter to the /t switch is treated like a pattern to match class
names inside the assembly. If we do not explicitly qualify the class name with
a .NET namespace, the tool will include all classes matching the supplied name.
We can even provide wildcards with the asterisk character (*), for example
/t:garage* would produce a schema with for the classes garage and garageCar.