How Can Individual Bits of a Word Be defined In XML?

benn (archive)

Usenet Archive
Joined
Mar 12, 2005
Messages
9
Reaction score
0
I have a microcontroller that I wish to send status data (via serial RS-232) out to a PC com port. Im trying to minimize the amount of bytes I transmit, so I want the micro to bit-pack various different fields into just a few bytes.

For example, one 8-bit byte will contain the following information:

Bit 0: Has Green Eyes
Bit 1: Has Brown Hair
Bit 2: Is Under 6 ft
...
Bit 7: Has Freckles

How can I efficiently use XML to tag each bit field?

Thanks!
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
I'm not sure what you're asking. If you want to simply build a map from the bits to strings describing them, that's easy enough to express in XML (it's just a table, after all).

But if you want to convert to and from the binary form, you need an actual programming language. If you've got a microcontroller, the right answer is generally assembler or something as near to that as possible, for efficiency's sake.

XML is a good interchange format for data, but is rarely the ideal format for specific tasks. Could you clarify why you think XML would be useful in this application?
 

benn (archive)

Usenet Archive
Joined
Mar 12, 2005
Messages
9
Reaction score
0
I'm not sure what you're asking. If you want to simply build a map from the bits to strings describing them, that's easy enough to express in XML (it's just a table, after all).

But if you want to convert to and from the binary form, you need an actual programming language. If you've got a microcontroller, the right answer is generally assembler or something as near to that as possible, for efficiency's sake.

XML is a good interchange format for data, but is rarely the ideal format for specific tasks. Could you clarify why you think XML would be useful in this application?

I know next to nothing about XML so this may not make sense at all or be totally inaccurate.

On the micro side, I can currently send raw serial binary (or ascii) data and display it on the pc via hyperterminal etc, however, I'd like to send the data in XML format so that it can be displayed intelligently on the PC side. I'm thinking XML might be a good format since the PC will always be able to display it properly even if I change the organization of the data bits/fields in the future.

Does this make sense? Could I send this bit-packed binary data (non- ascii) but with (ascii?) xml tags that tell the pc application about how the binary data is structured?

Thanks!
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
benn said:
Does this make sense? Could I send this bit-packed binary data (non- ascii) but with (ascii?) xml tags that tell the pc application about how the binary data is structured?

XML isn't magic. It's just portable syntax upon which languages can be built.

Yes, you could invent a markup language which describes the content of a block of binary data. Of course you'd then need an application on the recieving end which understands that description and uses it to access that data. Search the web for "XML data binding" for descriptions of how people have associated arbitrary data with XML structure in the past.

XML itself can not contain arbitrary binary data directly -- some characters have special meaning, some (eg line breaks) are specially processed, and some (depending on the version of XML) are simply forbidden. If you wanted to embed the binary data in the XML document, the usual solution is to do a base-64 encoding (same solution used in MIME attachments to SMTP mail).

But... If you're going to go to all that work, you may be defeating most of the advantages of having the data be bit-packed in the first place; you're adding nontrivial amounts of overhead. If you want to send unpacking instructions, I'd recommend sending them and the binary block as separate transfers. Or, quite possibly, giving up on binary and simply sending an XML-formatted text document which expresses the information.

XML is not "intelligent data", despite some early hype. It's just data that's structured so it can be processed intelligently. Someone still needs to provide the intelligence to create it, understand it, and do something with it.
 

benn (archive)

Usenet Archive
Joined
Mar 12, 2005
Messages
9
Reaction score
0
XML isn't magic. It's just portable syntax upon which languages can be built.

Yes, you could invent a markup language which describes the content of a block of binary data. Of course you'd then need an application on the recieving end which understands that description and uses it to access that data. Search the web for "XML data binding" for descriptions of how people have associated arbitrary data with XML structure in the past.

XML itself can not contain arbitrary binary data directly -- some characters have special meaning, some (eg line breaks) are specially processed, and some (depending on the version of XML) are simply forbidden. If you wanted to embed the binary data in the XML document, the usual solution is to do a base-64 encoding (same solution used in MIME attachments to SMTP mail).

But... If you're going to go to all that work, you may be defeating most of the advantages of having the data be bit-packed in the first place; you're adding nontrivial amounts of overhead. If you want to send unpacking instructions, I'd recommend sending them and the binary block as separate transfers. Or, quite possibly, giving up on binary and simply sending an XML-formatted text document which expresses the information.

XML is not "intelligent data", despite some early hype. It's just data that's structured so it can be processed intelligently. Someone still needs to provide the intelligence to create it, understand it, and do something with it.

Thanks, Im surprised xml does not support raw binary data.. perhaps xml 2.0 someday! I think, like you said, the way to go is to un-pack the binary data, represent each element in ascii, and then transmit it out with the xml tags around each of those elements. Just curious, do you happen to recommend any particular book / video on xml?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,051
Messages
3,104,251
Members
248,135
Latest member
tobystanx

Latest Threads

Top