[erlang-questions] Erlang and XML.

Ulf Wiger ulf@REDACTED
Thu Oct 16 23:07:20 CEST 2008


Something like this?

1> X = [{result,[],
               [{cols,[],[{col,[],[C]}
                            || C <- ColumnNames]},
                {rows,[],[{row,[],[{value,[],[V]}
                                        || V <- tuple_to_list(R)]}
                             || R <- Rows]}]}].

2> xmerl:export_simple(X, xmerl_xml).

If some column value is something other than a string, you'll
need to convert it first (e.g. integer_to_list(Int)).

BR,
Ulf W


2008/10/16 Dan Rubino <webaccounts@REDACTED>:
> Hi all,
>
> Been having a dabble with XMErl today. I am using Erlang on the server
> side to query an in-memory database via ODBC.
>
> As I am sure most of you know when you query a DB via ODBC in Erlang you
> get a structure something like this back:
>
> {selected, ColumnNames, Rows} = ...
>
> Where ColumnNames and Rows are of course lists. What I would like to do
> is convert these list into a very simple XML structure which I can
> return to a Java based client for easier processing.
>
> So something simple like the following for example (don't worry about
> col ordering):
>
>        <?xml version="1.0" ?>
>        <result>
>                <cols>
>                        <col></col>
>                </cols>
>                <rows>
>                        <row><value></value></row>
>                </rows>
>        </result>
>
> Having looked at XMErl there doesn't appear at first glance to be an
> easy and generic way in which I can do this.
>
> I am sure its something commonly done - any ideas?
>
> Many Thanks,
> Dan
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list