我在Erlang中使用ASN1模块进行解码。输出就像

{'UL-CCCH-Message',asn1_NOVALUE,
               {rrcConnectionRequest,
                {'RRCConnectionRequest',
                 {'tmsi-and-LAI',
                  {'TMSI-and-LAI-GSM-MAP',
                   [1,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,1,1,0,1,1,0,1,0,1,1,
                    1,1,0,1,0],
                   {'LAI',
                    {'PLMN-Identity',[2,2,6],[0,1]},
                    [0,1,1,1,1,0,0,1,1,0,0,0,1,1,0,1]}}},
                 terminatingBackgroundCall,noError,
                 {'MeasuredResultsOnRACH',
                  {'MeasuredResultsOnRACH_currentCell',
                   {fdd,
                    {'MeasuredResultsOnRACH_currentCell_modeSpecificInfo_fdd',
                     {'cpich-Ec-N0',39}}}},
                  asn1_NOVALUE},
                 asn1_NOVALUE}}}

如何输出XML而不是Erlang项?

有帮助吗?

解决方案

请记住,任何ERLANG术语(不是ASN.1模块)都可以通过这样的函数轻松输出为XML:

to_xml(X) when is_atom(X) ->
    "<atom>" ++ atom_to_list(X) ++ "</atom>"; % might want apostrophes
to_xml(X) when is_integer(X) ->
    "<integer>" ++ io_lib:format("~p", [X]) ++ "</integer>";
to_xml(X) when is_tuple(X) ->
    "<tuple size=" ++ tuple_size(X) ++ ">" ++ % or maybe want size implicit
        lists:foldr(fun(E, L) -> to_xml(E) ++ L end, [], tuple_to_list(X))
        ++ "</tuple>";
to_xml(X) when is_list(X) ->
    "<list>" ++ lists:foldr(fun(E, L) -> to_xml(E) ++ L end, [], X) ++ "</list>";
% etc...

其他提示

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top