Visual Basic.NET
  Home arrow Visual Basic.NET 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  
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? 
VISUAL BASIC.NET

Generating XML Schema Dynamically Using VB.NET 2005: Working With Attributes
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2006-02-20

    Table of Contents:
  • Generating XML Schema Dynamically Using VB.NET 2005: Working With Attributes
  • Generate XML Schema attributes dynamically using .NET framework: source code
  • Generate XML Schema attributes dynamically using .NET framework: explanation
  • Generate more XML Schema attributes dynamically using .NET framework: a sample schema and XML
  • Generate XML Schema attributes dynamically using the .NET framework: explanation

  • 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: Working With Attributes - Generate XML Schema attributes dynamically using .NET framework: explanation


    (Page 3 of 5 )

    This section explains the code fragment listed in the previous section.  Let us examine it part by part.  I am excluding some of the parts which are already explained in previous articles.  Let us take a look at the definitions of the main elements like “Organization”, “Employee” and so on.

            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 creates a new element (root) “Organization,” defines it as a complex type, and internally contains the elements in the form of a sequence.  The “Employee” element would look similar to the above element as follows:

            Dim eEmployee As New XmlSchemaElement()
            sqOrganization.Items.Add(eEmployee)
            eEmployee.Name = "Employee"
            eEmployee.MaxOccursString = "unbounded"
            Dim ctEmployee As New XmlSchemaComplexType()
            eEmployee.SchemaType = ctEmployee
            Dim sqEmployee As New XmlSchemaSequence
            ctEmployee.Particle = sqEmployee

    The only extras in the above code fragment are the following:

    • Add the “Employee” element as an element inside the “Organization” element (second statement)
    • The “Employee” element could be repeated any number of times within the “Organization” element (fourth statement).

    Besides the above two points, all the rest is the same.  As the “Employee” element itself is of the complex type, we can add any number of child elements to it.  Adding a “Name” element (child) to the “Employee” element can be done 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")

    And similarly I added another element, “Age,” as well.  After adding all the elements (or child elements) to the “Employee” element, we need to add the required attribute (which is “ID”).  The following code fragment shows how to add an attribute to a complex type element:

            Dim eID As New XmlSchemaAttribute()
            ctEmployee.Attributes.Add(eID)
            eID.Name = "ID"
            eID.Use = XmlSchemaUse.Required
            eID.SchemaTypeName = New XmlQualifiedName("int",
    "http://www.w3.org/2001/XMLSchema")

    According to the above code fragment, we create a new XML schema attribute (“eID”) and add it to the list of attributes related to the complex type of “Employee” element (second statement in the above code).  I wanted to make sure that “ID” is a compulsory attribute to every “Employee” element (which is enforced in the fourth statement).

    A reasonable XML document conforming to the above XML Schema would be as follows:

    <?xml version="1.0" encoding="UTF-8"?>
    <Organization xmlns:xsi="http://www.w3.org/2001/XMLSchema-
    instance
    "
    xsi:noNamespaceSchemaLocation="C:\Documents and
    Settings\Administrator\Desktop\ForDec\ForDec\XSLT\XMLExamples\02
    \Sample.xsd
    ">
          <Employee ID="1001">
                <Name>Jag</Name>
                <Age>27</Age>
          </Employee>
          <Employee ID="1002">
                <Name>Winner</Name>
                <Age>20</Age>
          </Employee>
    </Organization>

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Another article contributed for the series. Have it and enjoy. Any doubts (or...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek