Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Titan » XML encoding in TTCN-3 and Titan part 1: basics
XML encoding in TTCN-3 and Titan part 1: basics [message #1731681] Mon, 09 May 2016 08:38
Elemer Lelik is currently offline Elemer LelikFriend
Messages: 709
Registered: January 2015
Senior Member

Unlike the previously presented RAW and TEXT encoders, the XML encoder in Titan is standardized;
there's a separate part of the standard detailing XML and TTCN-3 interaction: Part 9: Using XML schema with TTCN-3

As explained in the JSON example

"XML schemas are the conceptual equivalent of TTCN-3 type definitions: they describe information structures
based on which instances of such structures can be derived, such instances can be validated against etc.
In case of XML schemas instances are often referred to as documents, in TTCN-3 these can be variables, templates or constants.
As the two abstractions are not exactly equivalent, some structural information in XML schemas (XSD files)
can be translated directly into TTCN-3 structures, but some information can be retained only in form of additional encoding information,
the intention being that from the TTCN-3 structures and encoding information we generate an XML instance
that validates against the schema used as starting point. Ultimately, as the result of conversion, we will be able
to communicate with an SUT using XML-based messages: we can decode such messages and verify them with TTCN-3s powerful
template matching mechanism, and also encode TTCN-3 variables, templates etc. into well-formed (syntactically sound)
and valid( verifiable against the schema) XML."

Mapping XML Schemas to TTCN-3 can be done implicitly or explicitly.
In case of an implicit mapping an internal representation is produced from the XML Schema, which
representation retains all the structural and encoding information. This internal representation is typically not
accessible by the user. This is largely similar with ASN.1 to TTCN-3 integration, where TTCN-3 imports structural definitions directly
from ASN.1 modules , which can be used then as base for templates etc.

In case of an explicit conversion, the information present in the XML Schema is mapped into accessible TTCN-3 code
and - the XML structural information which does not have its correspondent in TTCN-3 code - into accessible encoding

Titan prefers the latter approach , and this has to be taken into account for any code migration between tools.
A separate conversion utility xsd2ttcn is delivered together with other Titan binaries to perform the explicit conversion.

This utility processes the XML schema or schemas given as input and generates a TTCN-3 code decorated with a final
with { encode "XML" } instruction and types decorated with relevant
with { variant "" } instructions. The variants are detailed in the standard.

All that remains is to declare the external codec functions to make the auto-generated codecs visible from TTCN-3.
Needless to say , the auto-generated codecs can be directly used from C++, say from within a test port etc.
For instance, we can have a test port that accepts types converted from an XML schema; when sending, the templates are first XML-encoded,
then this XML is embedded into an HTTP message with appropriate headers and sent to SUT; at reception, the HTTP message is received, the
body extracted, XML-decoded and the template sent to the next layer.

The Titan XML codec will always generate namespaces in the root element:

<root xmlns:h="" xmlns:f="">
  <f:name>African Coffee Table</f:name>

but when decoding will understand the equivalent form with the namespaces appearing on their relevant levels only:
<h:table xmlns:h="">
<f:table xmlns:f="">
  <f:name>African Coffee Table</f:name>

In case of schemas that have been made extensible by using an any element, such as:

<xs:element name="person">
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
      <xs:any minOccurs="0"/>

the embedded opaque XML cannot be decoded , as the initial schema contains no structural information.
This will be returned as a string, which then can be subsequently decoded if the schema is known.
Often we see this kind of layering for messaging protocols where the outer layer is some kind of of a wrapper,
and the inner layer contains the actual protocol messages.

A good example for this is SOAP , see the previous topic

Next we will continue with a practical example of XML encoding-decoding.

Best regards
Previous Topic:Generating Java code from TTCN-3
Next Topic:How to work with optional fields
Goto Forum:

Current Time: Fri Mar 23 01:39:22 GMT 2018

Powered by FUDForum. Page generated in 0.01921 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software