Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Generating XML Schema Dynamically Using VB...
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 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Generating XML Schema Dynamically Using VB.NET 2005: Annotations and Nesting Complex Types - Understanding the dynamic generation of complex type in XML Schema


    (Page 2 of 4 )

    This section explains the code fragment listed in the previous section.  Let us examine it part by part.  We shall clear the textbox information using the following statement:

    Me.TextBox1.Text = ""

    Proceeding further, we have the following statement:

    Dim schema As New XmlSchema()

    The above statement starts our XML Schema.  Once a schema object is created, we can start adding our own elements, attributes, processing instructions, comments, etc to the same schema object.  Continuing on, we have the following:

    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

    The above code fragment creates the root element “Organization.”  As “Organization” internally may have some other elements, we make it of the complex type using “ctOrganization.”  We maintain sequence as the type of particle for the complex type. 

            Dim eEmployee As New XmlSchemaElement()
            sqOrganization.Items.Add(eEmployee)
            eEmployee.Name = "Employee"
            eEmployee.MaxOccursString = "unbounded"

    The above code fragment simply creates a new element called “Employee” and adds it to the “Organization” sequence particle.  You can also observe the “unbounded,” which allows the element “Employee” to be repeated any number of times.  Next we have the following:

            Dim ctEmployee As New XmlSchemaComplexType()
            eEmployee.SchemaType = ctEmployee
            Dim sqEmployee As New XmlSchemaSequence
            ctEmployee.Particle = sqEmployee

    As “Employee” is of the “complex type” (and not the “simple type”), we need to specify this point.  A complex type should also be joined with a “particle.”  The “particle” could be any of “All,” “Sequence,” “Choice” and so on (which I already explained in my “Designing your own XML Schema” series). 

    The above code fragment creates a new complex type (for “Employee” element) and a “sequence particle” (means that the elements should be provided in an orderly fashion).  Proceeding to the next fragment, we have:

            Dim eID As New XmlSchemaElement()
            sqEmployee.Items.Add(eID)
            eID.Name = "ID"
            eID.SchemaTypeName = New XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema")

    A “particle” generally contains some nested elements inside it (not every particle may contain nested elements).  In our case, the “Employee” element needs to be nested with two more elements (child elements), “ID” and “Name.” 

    The above code fragment creates a new element, names it “ID,” defines it as an “integer” data type, and finally adds it to the “sequence particle.”  Similarly, we add the “Name” element as follows:

            Dim eName As New XmlSchemaElement()
            sqEmployee.Items.Add(eName)
            eName.Name = "Name"
            eName.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")

    Further proceeding, we have the following:

            Dim nsmgr As New XmlNamespaceManager(New NameTable())
            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")

    The above two statements are used to define the namespace on which our schema gets adhered.  Finally, we have this snippet:

            Dim sw As New IO.StringWriter
            schema.Write(sw, nsmgr)
            Me.TextBox1.Text = sw.ToString

    The above code fragment creates a string writer where the schema gets generated (using the namespace we defined earlier).  Once the schema generation is complete we finally display it using the last line.

    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

    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - 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





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