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

Discussion in 'XML' started by benn, Mar 15, 2008.

  1. benn

    benn Guest

    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!
    benn, Mar 15, 2008
    #1
    1. Advertising

  2. 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?


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 17, 2008
    #2
    1. Advertising

  3. benn

    benn Guest

    On Mar 17, 6:25 am, Joseph Kesselman <>
    wrote:
    > 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?
    >
    > --
    > Joe Kesselman / Beware the fury of a patient man. -- John Dryden



    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!
    benn, Mar 18, 2008
    #3
  4. benn wrote:
    > 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.





    >
    > Thanks!
    >
    >



    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 19, 2008
    #4
  5. benn

    benn Guest

    On Mar 18, 5:22 pm, Joseph Kesselman <>
    wrote:
    > benn wrote:
    > > 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.
    >
    >
    >
    > > Thanks!

    >
    > --
    > Joe Kesselman / Beware the fury of a patient man. -- John Dryden


    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?
    benn, Mar 19, 2008
    #5
  6. benn wrote:
    > recommend any particular book / video on xml?


    http://www.ibm.com/xml -- lots of useful information from basic
    tutorials through examples through opinion pieces. (Not all of which IBM
    officially agrees with; they're edited as an almost-independent web
    journal.)


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Mar 20, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Oodini
    Replies:
    1
    Views:
    1,768
    Keith Thompson
    Sep 27, 2005
  2. Hybr1dz
    Replies:
    6
    Views:
    2,454
    Hybr1dz
    Apr 2, 2008
  3. harijay
    Replies:
    4
    Views:
    450
    harijay
    Feb 24, 2009
  4. Daku
    Replies:
    6
    Views:
    6,589
  5. googler

    Accessing individual bits in a number

    googler, May 19, 2008, in forum: Perl Misc
    Replies:
    0
    Views:
    108
    googler
    May 19, 2008
Loading...

Share This Page