Constructing typed objects from XML

5 posts / 0 new
Last post
Offline
Last seen: 4 months 1 week ago
Joined: 06/24/2016
Posts: 7
Constructing typed objects from XML

Hello,

 

I’m using DDS 5.3.1 .NET API. 

 

During testing it would be useful to save received messages to disk. I have found the data_to_string method in the type plugin, and it works well generating XML to be written to disk.  

However there does not seem to be anything to go the other way. That is, reading an XML file containing the information to be used, and then constructing and populating an object of the correct type to be sent.

Is there any information on how this could be done? The types that are used contain nested sequences of complex types, and the .NET framework XMLSerializer class (for example) cannot cope with the DDS::Sequence types.

 Any Ideas? 

Many Thanks,

rip
rip's picture
Offline
Last seen: 1 day 2 hours ago
Joined: 04/06/2012
Posts: 316

It's possible to do (have done it). 

1) Use the XML serialization to dump a bunch of messages

2) Use a tool like XMLSpy or similar, to ingest the messages and generate there-from an XML Schema Document.

3) Still in XMLSpy, generate a C/C++/Java binding for the XSD.

4) Compile, add the binding to a small application that simply reads XML files, and then convert from the internal format to the DDS Type instance (from an "engineer" viewpoint, this is tricky part, since it means understanding how XML is generally represented in memory, or it requires a writing a sax parsor or similar).  Not sure how many engineers come from an XML background into DDS XTypes, this might be an "everybody knows how to do this!" or not...).

5) Write the instance/sample.

It is also possible to write a single library that walks XML in-memory document structure (not the instance -- the /structure/) and creates/populates a lower-level RTI Connext DynamicData structure, and so make it entirely independent of the IDL-created types. 

RTI may have implemented this in the meantime. 

hth,

rip

Offline
Last seen: 4 months 1 week ago
Joined: 06/24/2016
Posts: 7

Hello,

The XMLSpy suggestion is interesting, and some research took me to the .NET code generator libraries which I did not know existed. I will also look at the DynamicData suggestion.

Many Thanks,

Fernando Garcia's picture
Offline
Last seen: 2 days 19 hours ago
Joined: 05/18/2011
Posts: 196

Hi sjevans,

Do you need to run all this logic from your test application? An alternative to storing the samples in XML and restoring them from your test application would be to use Recording Service. You would run an instance of Recording Service parallel to your application to store the test data and then run an instance of Replay to replay the data over DDS.

Also, If you don't mind storing the DynamicData samples in serialized format you could store them in binary format using the from_cdr_buffer and to_cdr_buffer APIs. That'd be significantly faster than the XML to- from-DynamicData conversions.

Thanks,
Fernando.

Offline
Last seen: 4 months 1 week ago
Joined: 06/24/2016
Posts: 7

Hello,

Sorry for the delay in replying.

In our situation we need the source for testing to be in a human readable format, as humans need to generate it, review it, and run the tests. The recording service can record things to disk, and replay messages later – but we still need to generate the messages in the first place for the recorder to record.

I’m going to have a look at XMLSpy, as was mentioned earlier and also look at using DynamicData or .NET Reflection to see if it is possible to generate something to automate reading and assembling samples.

It is possible that I will need to fall back on creating custom code to allow this.

Many Thanks,