[erlang-questions] How to set the toot tag with xmerl.

Bertil Karlsson bertil.karlsson@REDACTED
Mon Feb 9 09:52:11 CET 2009


Hi,

all record fields that are not set get their default values when the 
record is created.
So, you have to set the name field of the xmlElement RootEl to your 
desired value.

/Bertil

Salonee Sinha Roy wrote:
> Hi All
> I have the following erlang code from the xmerl sample in the 
> documentation.
>
> Data =
>   {bike,
>      [{year,"2003"},{color,"black"},{condition,"new"}],
>      [{name,
>          [{manufacturer,["Harley Davidsson"]},
>           {brandName,["XL1200C"]},
>           {additionalName,["Sportster"]}]},
>       {engine,
>          ["V-engine, 2-cylinders, 1200 cc"]},
>       {kind,["custom"]},
>       {drive,["belt"]}]}   ,
>
>     NewContent = lists:flatten([Data]),
>     RootEl = #xmlElement{content=NewContent},
>     Export=xmerl:export_simple([RootEl],xmerl_xml),
>     io:format("~p",[lists:flatten(Export)]).
>
> Running this method generates the following xml string
>
> "<?xml version=\"1.0\"?><undefined><bike year=\"2003\" color=\"black\" 
> condition=\"new\"><name><manufacturer>Harley 
> Davidsson</manufacturer><brandName>XL1200C</brandName><additionalName>Sportster</additionalName></name><engine>V-engine, 
> 2-cylinders, 1200 
> cc</engine><kind>custom</kind><drive>belt</drive></bike></undefined>"
>
> The root tag is <undefined>. How do I change this so that the root tag 
> is "<myxml>"
>
> Thanks
> Salonee
> ------------------------------------------------------------------------
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list