Warm tip: This article is reproduced from stackoverflow.com, please click
c# file-conversion

Reading/Parsing a .ddd (digital tachograph) file to XML in C#

发布于 2020-04-22 11:19:19

I'm fairly new to C# by the way and need to convert .ddd (digital tachograph output file extension) to .xml.

As a first step I should read the file, so I'm looking at examples. Every source of information I find are using .txt based examples on reading a file. The file type in my example, .ddd, is nowhere near that.

I'm thinking about binary read but not sure about that either. What is the correct way for this?

Questioner
Ege Bayrak
Viewed
186
C.Evenhuis 2015-06-26 20:12

To perform the conversion you need to know:

  • how to read binary data from a file
  • exactly what the file can contain (every single byte)
  • the desired output in Xml

Reading binary data from a file is fairly simple - the BinaryReader has all kinds of methods to access the data, especially if the data can be processed in a single forward pass (which seems to be the case). There are tons of BinaryReader examples out there.

What's more important is knowledge of what the data means. A single byte, with the value 0x20 could mean:

  • The SPACE character
  • The value 32
  • The byte could be the first byte of a UInt16 with an entirely different value
  • "The next block of data is 32 bytes long"
  • "The first block of data can be found at offset 32"
  • "The next block of data is metadata" (this byte indicating some sort of block type)
  • 32 bottles of beer on the wall

Without information about what each byte at each position means, you won't get anywhere.

Then with that information, and having read the file into some fitting class(es), the conversion to Xml could be as simple as passing the class to an XmlSerializer.