Visual Basic.NET
  Home arrow Visual Basic.NET arrow Generating XML Schema Dynamically Using VB...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Generating XML Schema Dynamically Using VB.NET 2005: Annotations and Nesting Complex Types
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2006-02-13

    Table of Contents:
  • Generating XML Schema Dynamically Using VB.NET 2005: Annotations and Nesting Complex Types
  • Understanding the dynamic generation of complex type in XML Schema
  • Generate XML Schema annotations dynamically using the .NET framework
  • Understanding the generation of XML Schema annotations dynamically using the .NET framework

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Generating XML Schema Dynamically Using VB.NET 2005: Annotations and Nesting Complex Types
    (Page 1 of 4 )

    This is the second article in a series concentrating on generating XML Schema dynamically using Visual Basic 2005. The series is mainly targeted at those who are familiar with XML, XML Schema and the .NET framework.
    A downloadable file for this article is available here.

    If you are new to this series, you can find the first article of this series here.  If you are new to XML, there exist several articles on XML alone on this website (try “igrep”).  If you are new to XML Schema, I strongly suggest you go through my series “Designing your own XML Schema.” 

    The entire solution for this article was developed using Visual Studio 2005 Professional Edition on Windows Server 2003 standard edition.  Some examples in this series may not be compiled successfully using Visual studio 2003, as some of the features in .NET 1.1 turned out to be obsolete in .NET 2.0.  For complete details you can refer to the link http://go.microsoft.com/fwlink/?linkid=14202.  Please note that some of the examples in this series may not be practical.  Those were designed only for explaining the particular concept.

    Generate XML Schema dynamically using .NET framework – more practical complex type

    Since I covered all the basics in my previous article, we shall now focus on more practical “complex types” in XML Schema.  Let us consider the following XML Schema:

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Organization">
        <xs:complexType>
          <xs:sequence>
            <xs:element maxOccurs="unbounded" name="Employee">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="ID" type="xs:int" />
                  <xs:element name="Name" type="xs:string" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    The above schema mainly contains a root element, “Organization.” Within the same element, we are trying to create as many “Employee” elements as possible.  Every “Employee” element internally will have “ID” and “Name” elements.  To generate the above XML Schema dynamically, we can consider the following code:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.TextBox1.Text = ""
            Dim schema As New XmlSchema()
     
            Dim eOrganization As New XmlSchemaElement
            schema.Items.Add(eOrganization)
            eOrganization.Name = "Organization"
            Dim ctOrganization As New XmlSchemaComplexType
            eOrganization.SchemaType = ctOrganization
            Dim sqOrganization As New XmlSchemaSequence
            ctOrganization.Particle = sqOrganization
     
            Dim eEmployee As New XmlSchemaElement()
            sqOrganization.Items.Add(eEmployee)
            eEmployee.Name = "Employee"
            eEmployee.MaxOccursString = "unbounded"
     
            Dim ctEmployee As New XmlSchemaComplexType()
            eEmployee.SchemaType = ctEmployee
     
            Dim sqEmployee As New XmlSchemaSequence
            ctEmployee.Particle = sqEmployee
     
            Dim eID As New XmlSchemaElement()
            sqEmployee.Items.Add(eID)
            eID.Name = "ID"
            eID.SchemaTypeName = New XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema")
     
            Dim eName As New XmlSchemaElement()
            sqEmployee.Items.Add(eName)
            eName.Name = "Name"
            eName.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
     
            Dim nsmgr As New XmlNamespaceManager(New NameTable())
            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
            Dim sw As New IO.StringWriter
            schema.Write(sw, nsmgr)
            Me.TextBox1.Text = sw.ToString
     
        End Sub

    I purposefully excluded “import” statements, because I already covered them in my previous article.  You can find a step-by-step explanation of the above code in the next section.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. This is second part of my series on "Generating XML Schema dynamically...
     

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway