问题描述
大家好,
我正在尝试编写一个程序,使我可以将二进制文件转换回人类可读的XML文件.
我想要一个小片段/示例/想法,以使程序(如果可能)从空的XML结构读取结构,并用二进制文件中的数据填充该结构,例如:
方案
< 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>
二进制文件
十六进制:
61 62 63 20 6C 69 62 72 61 72 79 00 FF 00 00 00 01 00 62 6F 6F 6F 6B 31 00 02 00 62 6F 6F 6B 32 00
ascii:
abc图书馆□□□□□□□book1□□□book2□
输出
< root>
< Library type ="LibraryInfo">
< LibraryName type ="string" value ="abc库"/>
< LibraryID type ="int32"值"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>
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>
推荐答案
这篇关于如何从二进制数据填充XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!