Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Generating Restrictions in XML Schema Dyna...
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 
VeriSign Whitepapers 
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 Restrictions in XML Schema Dynamically Using VB.NET 2005: Preliminaries
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2006-03-15

    Table of Contents:
  • Generating Restrictions in XML Schema Dynamically Using VB.NET 2005: Preliminaries
  • Restrictions (or constraints) in XML Schema: VB.NET sample
  • Restrictions (or constraints) in XML Schema: explanation
  • Extending the previous restriction with minExclusive
  • Differences between xxxExclusive and xxxInclusive

  • 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Generating Restrictions in XML Schema Dynamically Using VB.NET 2005: Preliminaries - Restrictions (or constraints) in XML Schema: 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. 

    Since 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 looks like this:

            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 of 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")

    And finally we need to focus on the restriction we applied to the XML schema.  The following is the main code fragment which implements the restriction. 

            Dim simpleType As New XmlSchemaSimpleType()
            eAge.SchemaType = simpleType
            Dim restriction As New XmlSchemaSimpleTypeRestriction()
            simpleType.Content = restriction
            restriction.BaseTypeName = New XmlQualifiedName
    ("integer", "http://www.w3.org/2001/XMLSchema")
            Dim maxInclusive As New XmlSchemaMaxInclusiveFacet()
            restriction.Facets.Add(maxInclusive)
            maxInclusive.Value = "100"

    To apply the restriction, first of all we need to create a “simple type.”  The content of the simple type needs to be assigned with an object based on the “XmlSchemaSimpleTypeRestriction” class.  Within the above code fragment, I created an object “restriction” based on the same class and assigned it to the “content” property of the simple type. 

    Any “restriction” is generally based on a certain base type and in this case, the base type would be an “integer” type.  Once the base type is fixed, we can now attach the appropriate facet for the restriction.  I used the “maxInclusive” facet which restricts based on the maximum value (inclusive of the value itself).  The maximum value to accept into the “Age” element is defined as “100.”  An acceptable 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


       · Hi, now you can work with restrictions in XML Schema using VB 2005. Any feedback is...
     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





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