Hi,
I have a binary data file that I want to store into a XML file. When I open the XML file it have to create the file inserting the binary data into it again.
Is it possible? I've seen that is possible to store images like qresource does.
Thanks,
Hi,
I have a binary data file that I want to store into a XML file. When I open the XML file it have to create the file inserting the binary data into it again.
Is it possible? I've seen that is possible to store images like qresource does.
Thanks,
Òscar Llarch i Galán
Base64 is the typical standard for storing binary data in XML.
Hi,
Sorry, but I didn't explained well.
I write an XML file that contains some data. On the other hand I have a file data that I want to store into my XML file. The binary file is from a 3rd party lib that stores some data in its way.
So I want to read the binary data content and write into the XML file in a tag like "<file_data>", then remove the binary file from disk. When I need to open the file I want to read the data of "<file_data>" tag and write it to a file to let the 3rd party open it.
It's just to get only one file.
Thanks,
Òscar Llarch i Galán
Yes, I'm going to assume you know how to read/write/delete disk files, so for the XML part, Qt has XML classes. You can read the binary file into memory, encode as Base64 (using QByteArray::toBase64) and then place the data into a CDATA section of the XML using QDomDocument::createCDATASection, QXmlStreamWriter::writeCDATA, or even just QXmlStreamWriter::writeCharacters.
^NyAw^ (21st January 2010)
I have similar issue.
I have a pointer to a buffer contains Binary-data .. I want to pull the values inside the buffer and encoding them before putting them in my xml format .. so I though of this:
QByteArray text;
for (int i=0; i<len_of_my_buffer; i++){
text[i] = *pointer_to_buffer[i];
}
create_xml_function(text.toBase64, "encoded data")
is this right ?
No. A QByteArray is created empty with no size, so accessing text[ i ] on an empty array will cause a crash. Do this:is this right ?
Qt Code:
create_xml_function( text64, "encoded_data" ); // spaces not allowed in XML tags!To copy to clipboard, switch view to plain text mode
Of course, you will want to add some error checking...
Bookmarks