XML
  Home arrow XML arrow Page 4 - 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 - Understanding the dynamic generation of complex type in XML Schema


    (Page 4 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, and so on to the same schema object.  Further proceeding, we have the following: 

            Dim eEmployee As New XmlSchemaElement()
            schema.Items.Add(eEmployee)
            eEmployee.Name = "Employee"

    The above code fragment simply creates a new element called “Employee” and adds it to the schema generator.  Further proceeding we have:

            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 “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 the “Employee” element) and a “sequence particle” (which means that the elements should be provided in an orderly fashion).  Further proceeding, we have the following:

            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 the nested elements inside it (not every particle may contain nested elements as well).  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 to which our schema gets adhered.  Proceeding further we have the following:

            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 is generated (using the namespace we defined earlier).  Once the schema generation is complete we finally display it using the last line.

    I hope that this article gives you a kick-start in generating dynamic XML Schemas using the .NET framework.  Another issue to pay attention to is that the examples I used in this demonstration may not be helpful in practical (or production) scenarios.  I strongly suggest you have a proper working draft design of the XML Schema you wanted to generate, and finally generate it using the code I present in this series.  A working draft may not be necessary if you want to generate the XML Schema from existing relational databases or other, similar kinds of structured information sources.

    Any comments, suggestions, feedback, bugs, errors, enhancements are highly appreciated at jag_chat@yahoo.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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