In this Walkthrough you will create an XML Purchase Order Schema As Part of A Windows Application Project. The Walkthrough Will Consist of Three Main Sections:
Creating a Windows Application Project and adding an XML Schema. CREATING A RELATIONAL TABLE:
Add and defining a new timextype object. Adding and defining a new element object. Editing generated XML Using the xml editor.
Creating a windows application and adding an XML Schema
To create a new windows copflication project
From the File menu, point to New, and then click Project to display the New Project dialog box. Depending on what language you want to use, select Visual C # Projects or Visual Basic Projects in the Project Types pane, and then select Windows Application. Name The Project Sampleschema.
To add an xml schema to the project
From The Project Menu, Choose Add New Item, THEN DOUBLE-CLICK The XML Schema Icon In The Add New Item Dialog Box. The XML Designer APPEARS.
Defining Simple and Complex Types
Before constructing the relational table, you will first build simple and complex type definitions that you will use to format specific elements of the purchase-order schema. The new types are built using existing XML data types, such as string and integer.
First You Will Define A Simple Type, Which Will Be named Statecode. This Simple Type Will Be used to limit the size of a string to two characters.
To Add an XML SimpleType to the Project
If not already open, double click the XMLSchema1.xsd file to bring up the XML Designer. Click the XML Schema tab of the Toolbox and drag a simpleType onto the design surface. Change the name of the simpleType by clicking the first text box in the header and replacing simpleType1 with stateCode. Set the base type for the stateCode type by clicking the drop-down list in the header and selecting string. Navigate to the first cell in the next row by pressing the TAB key. Select facet from the drop- down list. Press TAB to go to the next cell and select length from the drop-down list. TAB to the third cell of the same row, enter the value 2. This requires that the value entered into the State field be two characters. Your Statecode Should Look Like this in schema view: Click The Xml Tab At the Bottom Left of the Xml Designer to See the XML That Has Been Added:
xs: restriction>
xs: simpletype>
This Statecode Simple Type Will BE Used to Define The State Element WITHIN THE NEXT Section.
The complexType named addressType defines a set of elements that will appear in any element typed as addressType. For example, a billTo element will include information on names, addresses, and dates when its type is set to the previously defined addressType. By constructing the complex TYPE AND Using it with an element, you are get. for more information, see creating complex XML Types.
To Add an XML ComplexType to the Project
Click the Schema tab of the XML Designer. Drag a complexType from the XML Schema tab of the Toolbox onto the design surface. Change complexType1 to addressType to name the type. Add an XML attribute to addressType by clicking the first cell of the first row and selecting element from the drop-down list In the second column, change element1 to Name In the third column, accept the default value of string Add the following XML elements and set their names and types as follows:... Element nameData typeStreetstringCitystringStatestateCodePostalCodeinteger
Your AddressType Should Look Like this in schema view: to see the xml That Has Been added to your .xsd file, click the xml tab at the bottom of the designer. You will see the following xml:
xs: sequence>
xs: complexType>
Creating a reliceal Table
When you drag the element object from the Toolbox to the design surface, you are really adding an element containing an unnamed complexType. Including the unnamed complex type defines the element to be a relational table. Additional elements can then be added under the complexType to define the relation fields (or columns). If you define one of these new elements to be a new unnamed complexType, you are creating a nested relation inside of the parent relation with its own unique columns. For details see Tables, Columns, Keys, and Constraints in XML Schemas.Defining new unnamed complex type elements within the PurchaseOrder or Items element creates additional nesting in the schema. Within one purchase order there can be many Items, and within each Item, many additional elements (such as price, size, and SO ON). in The Following Procedure, An Element Items Is Added to The PurchaseOrder Relational Table and Typed As An Unnamed ComplexType. Because You Are Defining A New Relational Table, this causes a new element to appear on the design surface. Within the new items relation, adding the item element and setting its type to unnamed complexType, creates another relational table, which also appears on the design surface.
To add an xml element to the project
Click the Toolbox and from the XML Schema tab drag an element object onto the design surface. Change element1 to PurchaseOrder to name the element. You can leave the data type as (PurchaseOrder). Add an element to the purchase order by clicking the first cell Of the first row and selecting element from the drop - down list. name Type to addrestype. add the following XML Elements and set their nameless and types as stock:
Element nameData typebillToaddressTypeshipDatedateItemsunnamed complexTypeWhen you type the Item element to be anonymous, an additional element is added to the design surface, which is another relational table. In the Items element, add an element, name it Item, and set its type to Unnamed ComplexType. Your Purchase Order SHOULD LOOK LIKE THIS in schema view: The Following XML Has Now Been Added to your .xsd file:
xs: complexType>
xs: element>
xs: sequence>
xs: complexType>
xs: element>
xs: sequence>
xs: complexType>
xs: element>
EDITING XML
You can use the XML tab of the XML Designer to edit the XML that was generated when you added elements and types to the designer surface. The XML editor features IntelliSense and statement completion. An invalid statement is tagged with a red wavy line. Mousing over The IncorRect Statement Causes An Error Message To Appear.
To Edit XML
Click The XML Tab of The Xml Designer To View The Xml. Within The item Element, Change The Self-Closing Tag (
You have created three new elements - Quantity, Price, and ProductID -.. And defined data types for each Next type
xs: sequence>
xs: complexType>
xs: element>
xs: sequence>
xs: complexType>
xs: element>