BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
Schemas, xsd, xdr
XSD Schema Mappings
General XSD Limitations
Extracting Schemas for Nested Classes
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
<< 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 :180

 

Map Schemas using Model Groups

This section shows how we can map specific XML schema constructs to .NET classes with XML serialization attributes. All these mappings are automatically created by the XSD schema definition tool.

Sequence Model Groups

Single instance

<xs:complexType name="foo">

  <xs:sequence

    minOccurs="0"

    maxOccurs="1">

  <xs:element name="bar"

    type="xs:string" />

  <xs:element name="baz"

    type="xs:string" />

  </xs:sequence>

</xs:complexType>

<xs:element

  name="foobar" type="foo" />

[XmlRootAttribute("foobar", Namespace="urn:SequenceSchema.xsd",

  IsNullable=false)]

public class foo

{

    public string bar;

    public string baz;

}

Multi Instance

<xs:complexType name="multifoo">

  <xs:sequence minOccurs="0"

    maxOccurs="unbounded">

    <xs:element name="bar"

      type="xs:string" />

    <xs:element name="baz"

      type="xs:string" />

  </xs:sequence>

</xs:complexType>

<xs:element name="multifoobar"

  type="multifoo" />

public class multifoo

{

    [XmlElementAttribute("bar")]

    public string[] bar;   

}

Choice Model Groups

Unambiguous Particles

<xs:element name="Car">

  <xs:complexType

    mixed="false">

    <xs:choice minOccurs="1"

      maxOccurs="1">

      <xs:element minOccurs="1"

        maxOccurs="1"       

        name="LeasePayment"

        type="xs:int" />

      <xs:element minOccurs="1"

        maxOccurs="1"

        name="FinancePayment"

        type="xs:double" />

    </xs:choice>

  </xs:complexType>

</xs:element>

public class Car {

    [XmlElement("LeasePayment", typeof(int))]

    [XmlElement("FinancePayment", typeof(System.Double))]

    public object Item;

}

Ambiguous Particles

<xs:element name="Car">

  <xs:complexType

    mixed="false">

    <xs:sequence minOccurs="1"

      maxOccurs="1">

      <xs:choice minOccurs="1"

        maxOccurs="1">

        <xs:element minOccurs="1"

          maxOccurs="1"       

          name="LeasePayment"

          type="xs:int" />

        <xs:element minOccurs="1"

          maxOccurs="1"

          name="FinancePayment"

          type="xs:int" />

      </xs:choice>

    </xs:sequence>

  </xs:complexType>

</xs:element>

public class Car

{

  [XmlElementAttribute(

    "LeasePayment", typeof(int))]

  [XmlElementAttribute(

    "FinancePayment", typeof(int))]

  [XmlChoiceIdentifierAttribute(

    "ItemElementName")]

  public int Item;

  [XmlIgnoreAttribute()]

  public ItemChoiceType        

    ItemElementName;

}

[XmlTypeAttribute(

  IncludeInSchema=false)]

public enum ItemChoiceType

{

    LeasePayment,

    FinancePayment,

}


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
help desk support
swimming pool contractor
halloween masks
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