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

I

Ingolf Steinbach

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
 
J

Joseph J. Kesselman

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.
 
J

Jürgen Kahrs

Ingolf said:
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
 
I

Ingolf Steinbach

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.
 
P

Peter Flynn

Ingolf said:
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
 
I

Ingolf Steinbach

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
 
J

Joseph J. Kesselman

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.
 
P

Philippe Poulard

Ingolf Steinbach a écrit :
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 !
 
J

Jürgen Kahrs

Hello Ingolf,
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.
 
I

Ingolf Steinbach

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
 

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
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top