Altova XMLSpy 2024 Enterprise Edition

The default mapping of XML Schema types to C# data types is as follows.

 

XML Schema

C#

Remarks

xs:string

string


xs:boolean

bool


xs:decimal

decimal

xs:decimal has unlimited range and precision, mapped to decimal for efficiency reasons.

xs:float, xs:double

double


xs:long

long


xs:unsignedLong

ulong


xs:int

int


xs:unsignedInt

uint


xs:dateTime, date, time, gYearMonth, gYear, gMonthDay, gDay, gMonth

Altova.Types.DateTime


xs:duration

Altova.Types.Duration


xs:hexBinary and xs:base64Binary

byte[]

Encoding and decoding of binary data is done automatically.

xs:anySimpleType

string


 

All XML Schema types not contained in this list are derived types, and mapped to the same C# type as their respective base type.

 

Generated Classes

For each type in the schema, a class is generated that contains a member for each attribute and element of the type. The members are named the same as the attributes or elements in the original schema (in case of possible collisions, a number is appended). For simple types, assignment and conversion operators are generated. For simple types with enumeration facets, the methods GetEnumerationValue() and SetEnumerationValue(int) can be used together with generated constants for each enumeration value. In addition, the method StaticInfo() allows accessing schema information as one of the following types:

 

Altova.Xml.Meta.SimpleType

Altova.Xml.Meta.ComplexType

 

Classes generated from complex types include the method SetXsiType(), which enables you to set the xsi:type attribute of the type. This method is useful when you want to create XML instance elements of a derived type.

 

In addition to the classes for the types declared in the XML Schema, a document class (identified with "Doc" below) is generated. It contains all possible root elements as members, and various other methods. For more information about the class, see [YourSchema].[Doc].

 

Note:        The actual class name depends on the name of the .xsd schema.

 

For each member attribute or element of a schema type, a new class is generated. For more information about such classes, see:

 

[YourSchemaType].MemberAttribute

[YourSchemaType].MemberElement

 

Note:        The actual class names depend on the name of the schema attribute or element.

 

Error Handling

Errors are reported by exceptions. The following exception classes are defined in the namespace Altova:

 

Class

Base Class

Description

ConversionException

Exception

Exception thrown when a type conversion fails

StringParseException

ConversionException

A value in the lexical space cannot be converted to value space.

DataSourceUnavailableException

System.Exception

A problem occurred while loading an XML instance.

DataTargetUnavailableException

System.Exception

A problem occurred while saving an XML instance.

 

In addition, the following .NET exceptions are commonly used:

 

Class

Description

System.Exception

Base class for runtime errors

System.ArgumentException

A method was called with invalid argument values, or a type conversion failed.

System.FormatException

A value in the lexical space cannot be converted to value space.

System.InvalidCastException

A value cannot be converted to another type.

System.OverflowException

A source value cannot be represented in target domain.

 

Accessing schema information

The generated library allows accessing static schema information via the following classes:

 

Altova.Xml.Meta.Attribute

Altova.Xml.Meta.ComplexType

Altova.Xml.Meta.Element

Altova.Xml.Meta.SimpleType

 

The properties that return one of the metadata classes return null if the respective property does not exist.

© 2017-2023 Altova GmbH