Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone,
I am trying to write a program that allows me to convert a binary file back into a human-readable XML file.
I would like a small snippet/example/idea of how to do it to make (if possible) the program read the structure from an empty XML structure,and fill it with the data from the binary file, like for example:

scheme
<root>
<Library type="LibraryInfo">
<LibraryName type="string" value="" />
<LibraryID type="int32" value="" />
</Library>
<BookTable type="associative_array">
<Book type="pair">
<key type="int16" value="" />
<value type="string" value="" />
</Book>
</BookTable>
</root>

binary file
hex:
61 62 63 20 6C 69 62 72 61 72 79 00 FF 00 00 00 01 00 62 6F 6F 6B 31 00 02 00 62 6F 6F 6B 32 00
ascii:
abc library□□□□□□□book1□□□book2□

output
<root>
<Library type="LibraryInfo">
<LibraryName type="string" value="abc library" />
<LibraryID type="int32" value"255" />
</Library>
<BookTable type="associative_array">
<Book type="pair">
<key type="int16" value="1" />
<value type="string" value="book1" />
</Book>
<Book type="pair">
<key type="int16" value="2" />
<value type="string" value="book2" />
</Book>
</BookTable>
</root>
Posted
Updated 15-Apr-11 10:36am
v7
Comments
#realJSOP 15-Apr-11 13:59pm    
Have you noticed that your XML is invalid? Everything in yuor book element is malformed.
Renshou 15-Apr-11 15:44pm    
Sorry I had to run and didn't check, it looks like all the code I wrote got malformatted (and even missing some parts), how do tags work here? I'm used to BBCode
Renshou 15-Apr-11 15:54pm    
nvm I disabled html code and it seems fine now

There is no "convert".
(Misuing "convert" if a pandemic among CodeProject Inquirers. Who infected almost everyone?!)

There are no just "binary files". All files are binary, including text ones. So, there is XML on output and the following inputs: "binary file" + meta-data: 1) XML schema, 2) "binary file" format, 3) mapping between the two.

You provide #2 and #3 and then make you XML-generating function.

Based on the information you provided so far, that's all.

—SA
 
Share this answer
 
v2
Comments
Renshou 15-Apr-11 16:09pm    
You're right, I just couldn't find the right word for it to say the "text/ascii" counterpart rappresentation of data type's binary rappresentation like integers/booleans/etc. Also caused by the fact I'm italian and I'm still learning the right terminology, my apologies.
Sergey Alexandrovich Kryukov 15-Apr-11 16:56pm    
This is not a real problem (the terminology; I'm not a native English speaker myself, understand all kinds of possible problem). The real problem for you is the definition of the data model for your software, and then the technical aspects of XML will be quite solvable.

Thank you for understanding.
--SA
Renshou 15-Apr-11 21:43pm    
Umh well actually the problem is there's no data model... The program is the evil twin of a tool which accepts any well-formed XML file as input and outputs a serialized .dat file.
What I am trying to do is to deserialize these .dat files which could have any structure, by defining myself the structure and based on that my program tries to parse the raw input, I chose XML only because these raw files were originally XML files but I'm not tied to any format for the output.
I'm sorry if I misunderstood anything.
Ps. I'm the topic starter, just changed my displayed name for clarity
 
Share this answer
 
Comments
Renshou 15-Apr-11 16:14pm    
It's not what I am looking for, I'm currently trying to writing a program that parses data from a file using a reference "schema", thanks anyway

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900