Hex dump (e.g. S-Record) from XML via XSLT?

Discussion in 'XML' started by Ingolf Steinbach, Apr 21, 2008.

  1. Hi,

    I am searching for an XSLT which takes an input XML file like for
    instance

    <!-- preamble etc -->
    <xPosition>3572</xPosition>
    <yPosition>12345</yPosition>
    <temperature>3.142</temperature>
    <!-- ... -->

    and creates a hex dump (for instance S-Record format) using rules
    specifying that the number in xPosition shall be encoded as an
    unsigned 16-bit integer in big-endian byte order, the same for
    yPosition, and that <temperature> shall be encoded as a 32-bit IEEE
    floating point, again big-endian? The example above should generate a
    line like

    S10B00000DF430394049168764

    in the output.

    Any pointers to solutions to this problem are welcome. If the output
    is not S-Record but some other hex-dump like format, that is ok, too.

    Do you think that this is possible with an XSLT at all? Would it be
    possible without float or endianess support?

    Kind regards
    Ingolf
     
    Ingolf Steinbach, Apr 21, 2008
    #1
    1. Advertising

  2. > Do you think that this is possible with an XSLT at all? Would it be
    > possible without float or endianess support?


    XSLT is a turing-complete programming language, so it's certainly
    possible. People have done obscene things like writing
    eight-queens-problem solvers in XSLT, or rendering a series of chess
    moves as board grids, just to prove that it's possible.

    Whether it's *reasonable* is a separate question. XSLT is not the
    langauge I would select for this task.
     
    Joseph J. Kesselman, Apr 21, 2008
    #2
    1. Advertising

  3. Ingolf Steinbach schrieb:

    > and creates a hex dump (for instance S-Record format) using rules
    > specifying that the number in xPosition shall be encoded as an
    > unsigned 16-bit integer in big-endian byte order, the same for
    > yPosition, and that <temperature> shall be encoded as a 32-bit IEEE
    > floating point, again big-endian? The example above should generate a
    > line like
    >
    > S10B00000DF430394049168764
    >
    > in the output.


    Such output is probably easier to generate with
    a tool like XMLgawk:

    http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#How-to-traverse-the-tree-with-gawk
     
    Jürgen Kahrs, Apr 21, 2008
    #3
  4. On 21 Apr., 21:41, "Joseph J. Kesselman" <>
    wrote:
    > Whether it's *reasonable* is a separate question. XSLT is not the
    > langauge I would select for this task.


    Can someone recommend a tool* (other than XSLT) suitable for this
    task?

    Hopefully, interpreting a binary file and displaying the result in XML
    -- as well as the other way round (like in my situation) -- is not too
    uncommon...

    Kind regards
    Ingolf

    * Any tools (commercial, free ware, ...) are welcome.
     
    Ingolf Steinbach, Apr 21, 2008
    #4
  5. Ingolf Steinbach

    Peter Flynn Guest

    Ingolf Steinbach wrote:
    > On 21 Apr., 21:41, "Joseph J. Kesselman" <>
    > wrote:
    >> Whether it's *reasonable* is a separate question. XSLT is not the
    >> langauge I would select for this task.

    >
    > Can someone recommend a tool* (other than XSLT) suitable for this
    > task?


    Any decent programming language. C is the obvious choice.

    > Hopefully, interpreting a binary file and displaying the result in XML
    > -- as well as the other way round (like in my situation) -- is not too
    > uncommon...


    No indeed, but I would imagine your chances of finding a prewritten
    system for doing your precise task are virtually nil -- unless it
    happens to be a common format of data in your particular industry, in
    which case your industry's own web sites and forums are a more likely
    place to find it than here.

    ///Peter
     
    Peter Flynn, Apr 21, 2008
    #5
  6. On 21 Apr., 23:20, Peter Flynn <> wrote:
    > No indeed, but I would imagine your chances of finding a prewritten
    > system for doing your precise task are virtually nil -- unless it
    > happens to be a common format of data in your particular industry,

    [...]

    The idea was to have a tool which allows
    - describing the format of a binary file and
    - specification of the contents in (human readable) text based form
    (both preferably in XML) and doing the conversion from text based
    contents to binary.

    I would expect this to be quite a general task not limited to a small
    and specialized area of applications.

    Kind regards
    Ingolf
     
    Ingolf Steinbach, Apr 22, 2008
    #6
  7. Websearch on "data binding", which is the general term for mapping
    standard representations such as XML over arbitrary back-end data such
    as your binary dump.

    Various tools have been proposed. It's been a while since I've looked at
    this, so I'm not sure where the current state of the art stands.
     
    Joseph J. Kesselman, Apr 22, 2008
    #7
  8. On 21 Apr., 22:00, Jürgen Kahrs <>
    wrote:
    > Such output is probably easier to generate with
    > a tool like XMLgawk:
    >
    > http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#How-to-trav...


    Thank you, Jürgen, for the pointer. The examples in that document seem
    to suggest that xmlgawk is used mainly for rearranging data (replacing
    tags by other text but leaving the actual data mostly as is) rather
    than *transforming* the data. Is this observation correct?

    Kind regards
    Ingolf
     
    Ingolf Steinbach, Apr 22, 2008
    #8
  9. Ingolf Steinbach a écrit :
    > On 21 Apr., 22:00, Jürgen Kahrs <>
    > wrote:
    >> Such output is probably easier to generate with
    >> a tool like XMLgawk:
    >>
    >> http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#How-to-trav...

    >
    > Thank you, Jürgen, for the pointer. The examples in that document seem
    > to suggest that xmlgawk is used mainly for rearranging data (replacing
    > tags by other text but leaving the actual data mostly as is) rather
    > than *transforming* the data. Is this observation correct?


    Perhaps a more suitable tool would be a SAX parser : you read the input
    XML and you write whatever suitable for your application. SAX parsers
    are available in every popular language and your own part would consist
    for example when you match the <temperature> element on buffering the
    text content, parse it as a float, and dump it. Most languages supply
    such basic tools and you just have to put them all together.

    Regards,

    --
    Cordialement,

    ///
    (. .)
    --------ooO--(_)--Ooo--------
    | Philippe Poulard |
    -----------------------------
    http://reflex.gforge.inria.fr/
    Have the RefleX !
     
    Philippe Poulard, Apr 23, 2008
    #9
  10. Hello Ingolf,

    >> Such output is probably easier to generate with
    >> a tool like XMLgawk:
    >>
    >> http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#How-to-trav...

    >
    > Thank you, Jürgen, for the pointer. The examples in that document seem
    > to suggest that xmlgawk is used mainly for rearranging data (replacing
    > tags by other text but leaving the actual data mostly as is) rather
    > than *transforming* the data. Is this observation correct?


    No, transforming data is also possible. For example,
    I have written AWK scripts for doing linear regression
    (statistics) or a simple recursive-descent compiler.
    Just look at the other examples. For example the one
    that transforms an XML file into a graph drawing:

    http://home.vrweb.de/~juergen.kahrs/gawk/XML/xmlgawk.html#Converting-XML-data-into-tree-drawings
    http://home.vrweb.de/~juergen.kahrs/gawk/XML/docbook_chapter.jpg

    XMLgawk is based on a SAX parser and handles each
    tag separately. If you prefer to work with a DOM
    parser (because you need access to the complete
    DOM tree), then XMLgawk is not as convenient as
    you might need a tool.
     
    Jürgen Kahrs, Apr 23, 2008
    #10
  11. Thanks to all who have contributed to my search. The "data binding"
    hint lead to some interesting tools, but they all seem to be oriented
    towards de-serializing into C++/Java/whatever structures.
    Nevertheless, I believe that I'll find some progress there.

    Currently my approach looks like encoding the structure in XSD and
    writing a parser+validator+converter in C++ -- probably using some XML
    library for parsing and validating.

    Kind regards
    Ingolf
     
    Ingolf Steinbach, Apr 30, 2008
    #11
    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. Replies:
    10
    Views:
    6,356
    Neredbojias
    Aug 19, 2005
  2. halfdog
    Replies:
    12
    Views:
    12,557
  3. Matt
    Replies:
    4
    Views:
    3,445
    Socket
    Jul 29, 2004
  4. Bengt Richter
    Replies:
    6
    Views:
    505
    Juha Autero
    Aug 19, 2003
  5. Replies:
    7
    Views:
    1,037
    Mike Wahler
    Jul 1, 2007
Loading...

Share This Page