Altova XMLSpy 2024 Enterprise Edition

Character Types

The generated C++ code can be compiled with or without Unicode support. Depending on this setting, the types string_type and tstring will both be defined as std::string or std::wstring, consisting of narrow or wide characters. To use Unicode characters in your XML file that are not representable with the current 8-bit character set, Unicode support must be enabled. Pay special attention to the _T() macros. This macro ensures that string constants are stored correctly, whether you're compiling for Unicode or non-Unicode programs.

 

Data Types

The default mapping of XML Schema types to C++ data types is:

 

XML Schema

C++

Remarks

xs:string

string_type

string_type is defined as std::string or std:wstring

xs:boolean

bool


xs:decimal

double

C++ does not have a decimal type, so double is used.

xs:float, xs:double

double


xs:integer

__int64

xs:integer has unlimited range, mapped to __int64 for efficiency reasons.

xs:nonNegativeInteger

unsigned __int64

see above

xs:int

int


xs:unsignedInt

unsigned int


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

altova::DateTime


xs:duration

altova::Duration


xs:hexBinary and xs:base64Binary

std::vector<unsigned char>

Encoding and decoding of binary data is done automatically.

xs:anySimpleType

string_type


 

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::meta::SimpleType

altova::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 "CDoc" below) is generated. It contains all possible root elements as members, and various other methods. For more information about the class, see [YourSchema]::[CDoc].

 

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:

 

[YourSchema]::MemberAttribute

[YourSchema]::MemberElement

 

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

 

See also Example: Using the Schema Wrapper Libraries.

 

Error Handling

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

 

Class

Base Class

Description

Error

std::logic_error

Internal program logic error (independent of input data).

Exception

std::runtime_error

Base class for runtime errors.

InvalidArgumentsException

Exception

A method was called with invalid argument values.

ConversionException

Exception

Exception thrown when a type conversion fails.

StringParseException

ConversionException

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

ValueNotRepresentableException

ConversionException

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

OutOfRangeException

ConversionException

A source value cannot be represented in target domain.

InvalidOperationException

Exception

An operation was attempted that is not valid in the given context.

DataSourceUnavailableException

Exception

A problem occurred while loading an XML instance.

DataTargetUnavailableException

Exception

A problem occurred while saving an XML instance.

 

All exception classes contain a message text and a pointer to a possible inner exception.

 

Method

Purpose

string_type message()

Returns a textual description of the exception.

std::exception inner()

Returns the exception that caused this exception, if available, or NULL.

 

Accessing schema information

The generated library allows accessing static schema information via the following classes. All methods are declared as const. The methods that return one of the metadata classes return a NULL object if the respective property does not exist.

 

altova::meta::Attribute

altova::meta::ComplexType

altova::meta::Element

altova::meta::SimpleType

© 2017-2023 Altova GmbH