TypeCode creation from XML

6 posts / 0 new
Last post
Offline
Last seen: 8 years 2 weeks ago
Joined: 04/29/2016
Posts: 9
TypeCode creation from XML

Is there any available function to create a TypeCode from a XML definition (in C++)?
Preferably without creating any other DDS entities (I do not want a Reader/Writer involved at this point).

I whould like to be able to do something like this, where HelloWorld.xml is the generated XML output of rtiddsgen -convertToXml:

   DDS::TypeCode* tc = XMLtoTypeCode( "HelloWorld.xml" );
   DDS::DynamicData data( tc, DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT );


Regards
Micke

Fernando Garcia's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 05/18/2011
Posts: 200

Hi Micke,

If you have the XML definition in a file, you can use the following method:

DDS_TypeCode * DDS_TypeCodeFactory::create_tc_from_xml_file(
        const char * file_name,
        const char * type_name,
        struct DDS_StringSeq & include_paths,
        DDS_UnsignedLong unbounded_string_max_length,
        DDS_UnsignedLong unbounded_sequence_max_length,
        DDS_ExceptionCode_t & ex);

You will need to get an instance of the TypeCodeFactory via TypeCodeFactory::get_instance(), then you will need to construct a string of include paths in which you probably only need to include an element with the path to the file that contains the XML, get the filename and the typename and pass in the unbounded string and sequence maximum length. The exception code will let you know what is going on in case of an error.

Let me know if this solution works for you.

Fernando.

Offline
Last seen: 8 years 2 weeks ago
Joined: 04/29/2016
Posts: 9

Thank you, this was exactly what I was looking for :-) Don't know how I could have missed it when I was grepping the docs.

Works great even without any include paths.

Regards
/Micke

Offline
Last seen: 8 years 5 months ago
Joined: 03/22/2016
Posts: 6

is there an equivalent function in C? as far as I've seen there is nothing similar in the C API documentation.

regards,
marko

Fernando Garcia's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 05/18/2011
Posts: 200

Hi Marko,

There is a C equivalent function in C, but it does not seem to be publicly documented. Here is how to use it:

DDS_TypeCode * DDS_TypeCodeFactory_create_tc_from_xml_file(
        DDS_TypeCodeFactory * self,
        const char * file_name,
        const char * type_name,
        struct DDS_StringSeq * include_paths,
        DDS_UnsignedLong unbounded_string_max_length,
        DDS_UnsignedLong unbounded_sequence_max_length,
        DDS_ExceptionCode_t * ex);

You will need to provide in an instance of the DDS_TypeCodeFactory in the self argument. In C, you ca get a pointer to the factory using the following function:

DDS_TypeCodeFactory * DDS_TypeCodeFactory_get_instance();

Please, let me know if you need help using these functions.

Thanks,
Fernando.

Offline
Last seen: 3 years 3 weeks ago
Joined: 03/29/2021
Posts: 12

Hi Fernando,

It's a bit late but can you provide a concrete example of how to use the create_tc_from_xml_file() function?

Thanks.