加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Erlang的xml转换

发布时间:2020-12-16 05:19:54 所属栏目:百科 来源:网络整理
导读:概要:Erlang中xml的使用方法。 由于Erlang中数据的转换可以采用从tuple直接转成xml。 格式 : {Tag,Attributes,Content} {节点名,属性,元素} Tag IOString 说明: Tag = atom() Attributes = [{Name,Value}] Name = atom() Value = IOString | atom() | int

概要:Erlang中xml的使用方法。

由于Erlang中数据的转换可以采用从tuple直接转成xml。

格式

  • {Tag,Attributes,Content} {节点名,属性,元素}

  • Tag

  • IOString

    说明:

  • Tag = atom()

  • Attributes = [{Name,Value}]

  • Name = atom()

  • Value = IOString | atom() | integer()

例子:

[html] view plain copy
  1. -module(test).
  2. -compile(export_all).
  3. get_data()->
  4. <spanstyle="white-space:pre"></span>{filemeta,[{id,'/Foo'},{bar,12222221113}],[{name,["11"]},{age,["1"]}]}.
  5. start()->
  6. Temp=xmerl:export_simple([get_data()],xmerl_xml),
  7. io:format("~p~n",[Temp]),
  8. Test=lists:flatten(Temp),[Test]),248); line-height:18px"> ok.

结果:

copy

    ["<?xmlversion="1.0"?>",
  1. [[["<","filemeta",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> [["","id","="","/Foo","""],["","bar","12222221113","""]],248); line-height:18px"> ">"],108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> [[["</",0); background-color:inherit; font-weight:bold">>"]],248); line-height:18px"> [[">"]]],108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> [">"]]]]
  2. ?>filemetaid="/Foo"bar="12222221113">name>11age>1filemeta>"

注意事项:

1.属性的值可以是‘11’,“11”,11,或者是["11"]。最终都会被转变为字符串。

2.元素的格式必须是{Name,[Value]},Value==IOString。


ps:

增加encoding属性,因为默认为“<?xml version="1.0"?>”:

copy
    -define(xml_prolog,0); background-color:inherit; font-weight:bold">xmlversion="1.0"encoding="UTF-8"?>").
  1. Xml=xmerl:export_simple([data],xmerl_xml,[{prolog,?xml_prolog}]),

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读