【问题标题】:How to decode ASN.1 to XML with erlang如何使用 erlang 将 ASN.1 解码为 XML
【发布时间】:2011-06-10 07:22:39
【问题描述】:

我使用 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 术语?

【问题讨论】:

    标签: xml erlang asn.1


    【解决方案1】:

    请记住,任何 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...
    

    【讨论】:

    • 感谢您的回答。我写了一个这样的函数,但使用 xml 标记的记录名称。例如 "{'PLMN-Identity',[2,2,6],[0,1]}" ==> "2,2,60 ,1”。现在我正在尝试用记录字段名称替换“”。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-04
      • 1970-01-01
      • 2015-04-30
      • 1970-01-01
      • 2014-12-27
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多