PDA

View Full Version : xml with binary question



TheKedge
12th January 2006, 10:29
Hello all,
Erm, before I start, I'd just like to say ... "woooh, *nice* forum!"

anyway, I don't know much about xml, but before I start off learning about Qt XML classes and DOM and stuff, I've got a simple question.
It would be very handy for me if it were possible to have binary chunks in an xml file. Is that possible or practicable?

Can I read/write such files with the Qt classes?

example:
I'd like to have data in an ordered file so that I can parse to some place in the file to find my data (xml very handy here). The data might 10000 floats (say) and I rather not spend time parsing 10000 bits of text to floats (binary handy here). So, can I just stick binary chunks into an xml file and use the standard parsers.

any ideas?

TheKedge

(and mmmmmh, nice forum!)

high_flyer
12th January 2006, 12:49
I don't understand the meaning of "inserting binary data in to an xml file"...
But, from your description, it sounds like you dont need to really parse all the xml data, but that you are only looking for sertain places (where the floats are) in the data.
If so, I would just use binary file, and use some simple encoding, I would use some bit masks to mark the staring/ending point of the float data or something similar, this way you can run through the binary data very fast and apply bit masks on 32 bits at each time till you find a match, and only then you start "translating" the binary data to floats or what ever.

mcosta
12th January 2006, 13:19
It would be very handy for me if it were possible to have binary chunks in an xml file. Is that possible or practicable?


I don't think this is correct!
XML is a TEXT language for information sharing. In XML you must do define information in text format.

Bye

yop
12th January 2006, 13:38
I don't think this is correct!
XML is a TEXT language for information sharing. In XML you must do define information in text format.
And your thought is right.

It would be very handy for me if it were possible to have binary chunks in an xml file. Is that possible or practicable?

Don't mix apples and oranges.
If you want to use xml then you can put in the tree the offset to the binary data that interest you and then using that ofset access the actual binary data.

wysota
12th January 2006, 14:51
Of course you may have binary data in xml. All you need to do is to encode it into text (for example using base64 encoding) and place it into CDATA section if it's necessary.

TheKedge
12th January 2006, 14:51
ok, thanks for the help. I'll do it the right way then!

TheKedge

yop
12th January 2006, 17:04
Hmm shouldn't have posted before doing my homework:

There are at least three solutions to this problem:

* Embed the binary data directly in the XML document using the CDATA tag.
* Refer to the binary data using a URL.
* Encode the binary data into a text-based format that can be set as the contents of an XML element.http://uk.builder.com/manage/work/0,39026594,20268607,00.htm (and many more if you google around)

kandalf
12th January 2006, 23:21
I'm sorry for the little OT of this post, but I think the question is not "Can I put binary data into an XML file?" but "Would I post binary data into an XML file?"
I mean, what is the reason for putting binary data into an XML file?
What are the advantages of doing this?
I think it is not the best way to handle binary data.
Anyways, this is a full decision of the developer, and the question was answered.

Sorry for the OT, again.

Cheers.