Sample : Simple Hierarchy
Summary This sample shows a number of elements within a Hierarchy. It includes local (anonymous) & global complex types. It also shows how collections are manipulated within sequences & choices. Details This schema contains 2 globally defined elements AddressType, ItemType and Invoice. All of these objects can be used as the documentElement (root element) in a valid XML document. The Invoice object also contains a sequence, the sequence contains a number of child elements; InvoiceNo is a primitive DeliveryAddress is a element that conforms to the global element AddressType. BillingAddress is an optional (the corresponding property on the Invoice object may contain a null because of this) element that conforms to the global element AddressType. Item is a collection of elements conforming to the global element ItemType. Payment is a locally defined element, it in turn contains a choice of; an element 'VISA' or a collection of 'Vouchers' elements or an element 'Cash' which is untyped within the schema, and represented as a string within the generated code. |
SimpleHierarchy.xsd |
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:complexType name="AddressType"> <xs:sequence> <xs:element name="Forename" type="xs:string"/> <xs:element name="Surname" type="xs:string"/> <xs:element name="AddresLine1" type="xs:string"/> <xs:element name="AddresLine2" type="xs:string"/> <xs:element name="AddresLine3" type="xs:string" minOccurs="0"/> <xs:element name="AddresLine4" type="xs:string" minOccurs="0"/> <xs:element name="AddresLine5" type="xs:string"/> <xs:element name="PostCode" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:complexType name="ItemType"> <xs:sequence> <xs:element name="StockCode" type="xs:unsignedLong"/> <xs:element name="Description" type="xs:string"/> <xs:element name="UnitCost" type="xs:long"/> <xs:element name="Quantity" type="xs:unsignedInt"/> </xs:sequence> </xs:complexType> <xs:element name="Invoice"> <xs:complexType> <xs:sequence> <xs:element name="InvoiceNo" type="xs:unsignedInt"/> <xs:element name="DeliveryAddress" type="AddressType"/> <xs:element name="BillingAddress" type="AddressType" minOccurs="0"/> <xs:element name="Item" type="ItemType" maxOccurs="unbounded"/> <xs:element name="Payment"> <xs:complexType> <xs:choice> <xs:element name="VISA"> <xs:complexType> <xs:attribute name="CardNo" type="xs:string" use="required"/> <xs:attribute name="Expiry" type="xs:gYearMonth" use="required"/> </xs:complexType> </xs:element> <xs:element name="Vouchers" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="VoucherNo" type="xs:unsignedLong" use="required"/> <xs:attribute name="VoucherValue" type="xs:unsignedLong" use="required"/> </xs:complexType> </xs:element> <xs:element name="Cash"/> </xs:choice> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> |
Schema Diagrams |
|
Sample Name | Description | C++ | C# | Java | VB.Net | VB6 |
Navigation | The sample demonstrates how to navigate a simple Hierarchy of elements, including optional elements, choices, and collections. The sample shows the Invoice as the root element, it contains the optional element BillingAddress. It also contains 2 Item elements, showing how collections of elements can be manipulated. The Payment element contains a VISA element, this can be determined by checking the value of invoice->GetPayment()->GetChoiceSelectedElement(), this will determine which of the 3 possible elements are selected. |
Example | Example | Example | Example | Example |
Collections in a choice | The sample builds on the previous sample, and demonstrates how to deal with a choice that contains a collection of elements. | Example | Example | Example | Example | Example |
Main Menu |