BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
Schemas, xsd, xdr
Creating Schemas from Assemblies
Strongly Typed .NET DataSet
XSD schemaLocation
Selecting Elements in Schemas
Specifying Namespaces
XSD targetNamespace
XSD Schemas
Convert XDR to XSD
Learn XSD Schemas .NET Tutorial
Conversion of genealogical files to XML with a DTD
AccessXML
Sorting by date without using a schema
Validating and enforcing a list of attribute values
Entity name support without DTDs
The Loss of Formatting When Adding a Schema
simple xml notepad
Schemas using DBMS_XMLQuery Package
Tips for Designing a DTD - Part 1 of 4
Tips for Designing a DTD- Part 2 of 4 : Semi-Structured Documents
Tips for Designing a DTD- Part 3 of 4 : Database Oriented Data
<< reBlogger
SEO >>

By :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

public class Garage

{

  public Garage()      { }

  public class garageCar

  {

    public garageCar(){}

    [System.Xml.Serialization.XmlAttributeAttribute()]

    public string make;

    [System.Xml.Serialization.XmlAttributeAttribute()]

    public string model;

    [System.Xml.Serialization.XmlAttributeAttribute()]

    public string year;

  }

  public string desc;

  [System.Xml.Serialization.XmlElementAttribute("car")]

  public Car[] car;

}

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

<?xml version="1.0" encoding="utf-8"?>

<xs:schema elementFormDefault="qualified"

  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Garage" nillable="true" type="Garage" /> | #1

  <xs:complexType name="Garage">

    <xs:sequence>

      <xs:element minOccurs="0"

        maxOccurs="1" name="desc" type="xs:string" />

      <xs:element minOccurs="0"

        maxOccurs="unbounded" name="car" type="garageCar" />

    </xs:sequence>

  </xs:complexType>

  <xs:complexType name="garageCar">

    <xs:attribute name="make" type="xs:string" />

    <xs:attribute name="model" type="xs:string" />

    <xs:attribute name="year" type="xs:string" />

  </xs:complexType>

</xs:schema>

(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:

<?xml version="1.0" encoding="utf-8" ?>

<xs:schema elementFormDefault="qualified"

  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="garageCar" nillable="true" type="garageCar" />

  <xs:complexType name="garageCar">

    <xs:attribute name="make" type="xs:string" />

    <xs:attribute name="model" type="xs:string" />

    <xs:attribute name="year" type="xs:string" />

  </xs:complexType>

</xs:schema>

 

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.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

An immediate job opportunity as a B
Software Developers Needed in Charl
Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C

View all Jobs (Add yours)
View all CV (Add yours)



answering service
fax server
swimming pool contractor
halloween mask
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP