XML
  Home arrow XML arrow 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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 34
    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


    (Page 1 of 4 )

    This is the first 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.

    There exist several articles on XML alone on this website.  If you are new to XML Schema, I strongly suggest you go through my series “Designing your own XML Schema.” That series will introduce you to all the necessary concepts in designing XML schemas, even if you are a beginner.

    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 compile 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

    Generating XML Schema dynamically using the .NET framework: preliminaries

    Not everyone knows that we can generate XML schema dynamically using the .NET framework.  This happened to be the situation in one of my projects.  And I just wanted to share my knowledge with you.  I experienced few troubles when I ported my .NET 1.1 applications to .NET 2.0 (due to obsolescence).  During this series, we shall explore and address the most important issues on this topic.

    First of all, we need to import two namespaces, namely “System.Xml” and “System.Xml.Schema”.  Both of them are available in the “System.Xml” assembly.  So, we need to refer (using “Add Reference”) to “System.Xml” before importing the two namespaces.

    For this sample, I just created a simple Windows application using Visual Studio with a single button and multi-lined textbox.  When I hit the button it would generate some XML Schema in the multi-lined textbox.  So, I suggest you design the same before you proceed with the code.

    Now let us consider that I would like to have the following XML Schema to be generated:

    <?xml version="1.0" encoding="utf-16"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Organization" type="xs:string" />
    </xs:schema>

    The above XML Schema simply declares a single element, “Organization.”  To generate the above XML Schema dynamically, copy and paste the following code and execute it with the application:

    Imports System
    Imports System.Xml
    Imports System.Xml.Schema
    .
    .
    .
    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 elementOrg As New XmlSchemaElement()
            schema.Items.Add(elementOrg)
            elementOrg.Name = "Organization"
            elementOrg.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

    That’s it.  Just execute the application and hit the button. It will show the previous XML Schema in to the textbox.  You can find an explanation for 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-2010 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek