Visual Basic.NET
  Home arrow Visual Basic.NET 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 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
JMSL Numerical Library 
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

    Ajax Application Generator Generate database 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 - Understanding the generation of XML Schema annotations dynamically using the .NET framework


    (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, etc to the same schema object.  Further proceeding, we have the following:

        Dim eOrganization As New XmlSchemaElement
          schema.Items.Add(eOrganization)
          eOrganization.Name = "Organization"
      
    .
      
    .
      
    .
          Dim ctOrganization As New XmlSchemaComplexType
          eOrganization.SchemaType = ctOrganization

    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”. 

    Continuing on, we have the following:

    Dim aOrganization As New XmlSchemaAnnotation
            eOrganization.Annotation = aOrganization
            Dim dOrganization As New XmlSchemaDocumentation
            aOrganization.Items.Add(dOrganization)
            dOrganization.Markup = TextToNodeArray("States in the Pacific Northwest of US")

    The above code fragment first creates an annotation (or “<annotation>”) and adds the annotation to the “Organization” element.  Once added, we then create a documentation element (or “<documentation>”) and add this to the annotation element.  To have some information to place as part of the documentation, you can use the last statement.  The “TextToNodeArray” is defined as follows:

      Public Shared Function TextToNodeArray(ByVal text As String) As XmlNode()
            Dim doc As New XmlDocument()
            Return New XmlNode(0) {doc.CreateTextNode(text)}
        End Function

    The above function mainly accepts some message as a string and returns an array of “XmlNode”s.  It is required for the “Markup” property of documentation, which accepts the same.

    Next, we have the following code snippet:

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

    At the moment, I am not focusing on validating or compiling the XML Schema dynamically. We can have all of those features in the upcoming articles.  Sign up for the newsletter to get yourself notified when they're published.

    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. This is second part of my series on "Generating XML Schema dynamically...
     

    VISUAL BASIC.NET ARTICLES

    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - 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...





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