XML
  Home arrow XML arrow Page 3 - 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 
Mobile Linux 
App Generation ROI 
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? 
XML

Generating XML Schema Dynamically Using VB.NET 2005: Essentials
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    2006-02-06

    Table of Contents:
  • Generating XML Schema Dynamically Using VB.NET 2005: Essentials
  • Understanding the dynamic generation of XML Schema using the .NET framework
  • Generating XML Schema dynamically using the .NET framework: complex type
  • Understanding the dynamic generation of complex type in XML Schema

  • 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


    Generating XML Schema Dynamically Using VB.NET 2005: Essentials - Generating XML Schema dynamically using the .NET framework: complex type


    (Page 3 of 4 )

    Since I covered the basics in the previous sections, we shall now focus on “complex types” in XML Schema.  Generating “complex types” is a bit more complicated than generating “simple types.”  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="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:schema>

    I know that the above XML schema is not at all practical.  But I will be using it only for demonstration.  I meant it only to explain the .NET code better (and not XML Schema).  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 eEmployee As New XmlSchemaElement()
            schema.Items.Add(eEmployee)
            eEmployee.Name = "Employee"
     
            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 purposely excluded the “import” statements, as I already covered those in previous sections.  You can find the explanation of the above code in the next section.

    More XML Articles
    More By Jagadish Chaterjee


       · Hello guys, dig into creating dynamic XML Schemas using vb.net 2005 using this...
     

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT