views:

32

answers:

1

Are there any resources on how to represent (script) code in XML? Libraries, XML schema definitions for this?

What I want to try is to generate a XML representation of (at first) simple script code (such as Bash shell scripts). So I would need support for variables, if/else, loops. Later on I want to be able to write language-independent test cases in XML and have them parsed and executed in different language environments.

+2  A: 

While this does work, you won't like the result very much: XML is very expressive. So a simple a = b + c would become

<assign>
    <variable>a</variable>
    <add>
        <variable>b</variable>
        <variable>c</variable>
    </add>
</assign>

That's a mere 1675% increase in code size (and a matching decrease in readability).

It's much more simple to define a simple DSL (domain specific language). This DSL would be parsed into an AST (abstract syntax tree). Now you just need to write an interpreter for this AST in each language. While the AST (being a tree) is very similar to XML, the way to build it is much more comfortable for the user when you use a DSL.

Aaron Digulla
True, true. Too verbose, not a great idea.
desolat