ATerm To Xml

XT -- A Bundle of Program Transformation Tools

Summary

Converts an ATerm to a comparable XML document.

Description

The tools aterm2xml and xml2aterm support the conversion from ATerm to XML and vice versa. Since applications have different needs, there are three conversion modes available: implicit, explicit, and very explicit.

  • The explicit mode is the default mode and supports a roundtrip for almost all ATerms (that is, an ATerm can be converted to XML and back without changing its structure).

  • The implicit mode does not support such a roundtrip, but the XML is usually more attractive. Use this mode if you only want to export some ATerm to an XML application. The name 'implicit' is related to the more implicit structure in the resulting XML.

  • The very explicit mode supports a roundtrip for all ATerms. This mode is the way to go if you need the guarantee that a roundtrip preserves the structure of all your ATerms.

The structure of the XML documents in the very explicit mode is generic: there are no language specific elements in these XML documents. The structure is described a RELAX NG schema.

Future Work

In a future release we will add support for a round trip in the implicit mode, based on schema/rtg information. This has already been implemented, but needs to be updated and refactored.

Examples

The following invocations illustrate how to invoke the tools:

$ aterm2xml -i foo.trm                  # convert to explicit xml
$ aterm2xml -i foo.trm | xml2aterm      # convert to explicit xml and back
$ aterm2xml -i foo.trm --implicit       # convert to implicit xml
$ aterm2xml -i foo.trm --very-explicit  # convert to very explicit xml

The following tables explain the differences between the three explicity modes that are support by aterm2xml.

Explicit XML

ATerm Explicit XML Back to ATerm
foo
<foo/>
foo
foo(1)
<foo>
  <int>1</int>
</foo>
foo(1)
1
<int>1</int>
1
"abc"
<string>abc</string>
"abc"
()
<tuple/>
()
(1, 2)
<tuple>
  <int>1</int>
  <int>2</int>
</tuple>
(1,2)
[]
<list/>
[]
[1, 2]
<list>
  <int>1</int>
  <int>2</int>
</list>
[1,2]
fred([foo, bar])
<fred>
  <list>
    <foo/>
    <bar/>
  </list>
</fred>
fred([foo,bar])
fred(None, [foo, bar])
<fred>
  <None/>
  <list>
    <foo/>
    <bar/>
  </list>
</fred>
fred(None,[foo,bar])
fred(Some(barney), [foo, bar])
<fred>
  <Some>
    <barney/>
  </Some>
  <list>
    <foo/>
    <bar/>
  </list>
</fred>
fred(Some(barney),[foo,bar])
fred("foo", "bar")
<fred>
  <string>foo</string>
  <string>bar</string>
</fred>
fred("foo","bar")
foo{fred}
<foo/>
foo

Implicit XML

ATerm Implicit XML Back to ATerm
foo
<foo/>
foo
foo(1)
<foo>1</foo>
foo("1")
1
not possible not possible
"abc"
not possible not possible
()
not possible not possible
(1, 2)
not possible not possible
[]
not possible not possible
[1, 2]
not possible not possible
fred([foo, bar])
<fred>
  <foo/>
  <bar/>
</fred>
fred(foo,bar)
fred(None, [foo, bar])
<fred>
  <foo/>
  <bar/>
</fred>
fred(foo,bar)
fred(Some(barney), [foo, bar])
<fred>
  <barney/>
  <foo/>
  <bar/>
</fred>
fred(barney,foo,bar)
fred("foo", "bar")
<fred>foobar</fred>
fred("foobar")
foo{fred}
<foo/>
foo

Very Explicit XML

ATerm Very Explicit XML Back to ATerm
foo
<appl fun="foo"/>
foo
foo(1)
<appl fun="foo">
  <int>
    <value>1</value>
  </int>
</appl>
foo(1)
1
<int>
  <value>1</value>
</int>
1
"abc"
<string>
  <value>abc</value>
</string>
"abc"
()
<tuple/>
()
(1, 2)
<tuple>
  <int>
    <value>1</value>
  </int>
  <int>
    <value>2</value>
  </int>
</tuple>
(1,2)
[]
<list/>
[]
[1, 2]
<list>
  <int>
    <value>1</value>
  </int>
  <int>
    <value>2</value>
  </int>
</list>
[1,2]
fred([foo, bar])
<appl fun="fred">
  <list>
    <appl fun="foo"/>
    <appl fun="bar"/>
  </list>
</appl>
fred([foo,bar])
fred(None, [foo, bar])
<appl fun="fred">
  <appl fun="None"/>
  <list>
    <appl fun="foo"/>
    <appl fun="bar"/>
  </list>
</appl>
fred(None,[foo,bar])
fred(Some(barney), [foo, bar])
<appl fun="fred">
  <appl fun="Some">
    <appl fun="barney"/>
  </appl>
  <list>
    <appl fun="foo"/>
    <appl fun="bar"/>
  </list>
</appl>
fred(Some(barney),[foo,bar])
fred("foo", "bar")
<appl fun="fred">
  <string>
    <value>foo</value>
  </string>
  <string>
    <value>bar</value>
  </string>
</appl>
fred("foo","bar")
foo{fred}
<appl fun="foo">
  <anno>
    <appl fun="fred"/>
  </anno>
</appl>
foo{fred}

Examples for 0.13

In StrategoXT? the representations have changed a little bit.

Explicit XML

ATerm Explicit XML Back to ATerm
foo
<foo xmlns:at="http://aterm.org"/>
foo
foo(1)
<foo xmlns:at="http://aterm.org">
  <at:int>1</at:int>
</foo>
foo(1)
1
<at:int xmlns:at="http://aterm.org">1</at:int>
1
"abc"
<at:string xmlns:at="http://aterm.org">abc</at:string>
"abc"
()
<at:tuple xmlns:at="http://aterm.org"/>
()
(1, 2)
<at:tuple xmlns:at="http://aterm.org">
  <at:int>1</at:int>
  <at:int>2</at:int>
</at:tuple>
(1,2)
[]
<at:list xmlns:at="http://aterm.org"/>
[]
[1, 2]
<at:list xmlns:at="http://aterm.org">
  <at:int>1</at:int>
  <at:int>2</at:int>
</at:list>
[1,2]
fred([foo, bar])
<fred xmlns:at="http://aterm.org">
  <at:list>
    <foo/>
    <bar/>
  </at:list>
</fred>
fred([foo,bar])
fred(None, [foo, bar])
<fred xmlns:at="http://aterm.org">
  <None/>
  <at:list>
    <foo/>
    <bar/>
  </at:list>
</fred>
fred(None,[foo,bar])
fred(Some(barney), [foo, bar])
<fred xmlns:at="http://aterm.org">
  <Some>
    <barney/>
  </Some>
  <at:list>
    <foo/>
    <bar/>
  </at:list>
</fred>
fred(Some(barney),[foo,bar])
fred("foo", "bar")
<fred xmlns:at="http://aterm.org">
  <at:string>foo</at:string>
  <at:string>bar</at:string>
</fred>
fred("foo","bar")
foo{fred}
<foo xmlns:at="http://aterm.org">
  <at:anno>
    <fred/>
  </at:anno>
</foo>
foo{fred}

Very Explicit XML

ATerm Very Explicit XML Back to ATerm
foo
<at:appl xmlns:at="http://aterm.org" at:fun="foo"/>
foo
foo(1)
<at:appl xmlns:at="http://aterm.org" at:fun="foo">
  <at:int>
    <at:value>1</at:value>
  </at:int>
</at:appl>
foo(1)
1
<at:int xmlns:at="http://aterm.org">
  <at:value>1</at:value>
</at:int>
1
"abc"
<at:string xmlns:at="http://aterm.org">
  <at:value>abc</at:value>
</at:string>
"abc"
()
<at:tuple xmlns:at="http://aterm.org"/>
()
(1, 2)
<at:tuple xmlns:at="http://aterm.org">
  <at:int>
    <at:value>1</at:value>
  </at:int>
  <at:int>
    <at:value>2</at:value>
  </at:int>
</at:tuple>
(1,2)
[]
<at:list xmlns:at="http://aterm.org"/>
[]
[1, 2]
<at:list xmlns:at="http://aterm.org">
  <at:int>
    <at:value>1</at:value>
  </at:int>
  <at:int>
    <at:value>2</at:value>
  </at:int>
</at:list>
[1,2]
fred([foo, bar])
<at:appl xmlns:at="http://aterm.org" at:fun="fred">
  <at:list>
    <at:appl at:fun="foo"/>
    <at:appl at:fun="bar"/>
  </at:list>
</at:appl>
fred([foo,bar])
fred(None, [foo, bar])
<at:appl xmlns:at="http://aterm.org" at:fun="fred">
  <at:appl at:fun="None"/>
  <at:list>
    <at:appl at:fun="foo"/>
    <at:appl at:fun="bar"/>
  </at:list>
</at:appl>
fred(None,[foo,bar])
fred(Some(barney), [foo, bar])
<at:appl xmlns:at="http://aterm.org" at:fun="fred">
  <at:appl at:fun="Some">
    <at:appl at:fun="barney"/>
  </at:appl>
  <at:list>
    <at:appl at:fun="foo"/>
    <at:appl at:fun="bar"/>
  </at:list>
</at:appl>
fred(Some(barney),[foo,bar])
fred("foo", "bar")
<at:appl xmlns:at="http://aterm.org" at:fun="fred">
  <at:string>
    <at:value>foo</at:value>
  </at:string>
  <at:string>
    <at:value>bar</at:value>
  </at:string>
</at:appl>
fred("foo","bar")
foo{fred}
<at:appl xmlns:at="http://aterm.org" at:fun="foo">
  <at:anno>
    <at:appl at:fun="fred"/>
  </at:anno>
</at:appl>
foo{fred}

Implicit XML

ATerm Implicit XML Back to ATerm
foo
<foo xmlns:at="http://aterm.org"/>
foo
foo(1)
<foo xmlns:at="http://aterm.org">1</foo>
foo("1")
1
not possible not possible
"abc"
not possible not possible
()
not possible not possible
(1, 2)
not possible not possible
[]
not possible not possible
[1, 2]
not possible not possible
fred([foo, bar])
<fred xmlns:at="http://aterm.org">
  <foo/>
  <bar/>
</fred>
fred(foo,bar)
fred(None, [foo, bar])
<fred xmlns:at="http://aterm.org">
  <foo/>
  <bar/>
</fred>
fred(foo,bar)
fred(Some(barney), [foo, bar])
<fred xmlns:at="http://aterm.org">
  <barney/>
  <foo/>
  <bar/>
</fred>
fred(barney,foo,bar)
fred("foo", "bar")
<fred xmlns:at="http://aterm.org">foobar</fred>
fred("foobar")
foo{fred}
<foo xmlns:at="http://aterm.org">
  <at:anno>
    <fred/>
  </at:anno>
</foo>
foo{fred}