查看源代码 xmerl (xmerl v2.1)

用于将 XML 数据导出为外部格式的函数。

摘要

类型

一个回调模块或继承的回调模块列表。

标准的、格式良好的 XML 内容元素。

“简单形式”的 XML 属性。

“简单形式”的 XML 内容元素。

记录 #xmlAttribute{}

记录 #xmlComment{}

记录 #xmlDecl{}

记录 #xmlDocument{}

记录 #xmlElement{}

记录 #xmlNamespace{}

记录 #xmlNsNode{}

记录 #xmlPI{}

记录 #xmlText{}

函数

查找给定模块的继承回调模块列表。

直接导出标准 XML 内容,无需进一步的上下文。

直接导出标准 XML 元素,无需进一步的上下文。

用于在 XML 文档解析(SAX 样式)期间进行动态导出。

导出“简单形式”的 XML 内容。

直接导出简单 XML 内容,无需进一步的上下文。

直接导出简单的 XML 元素,无需进一步的上下文。

类型

链接到此类型

callback()

查看源代码 (未导出)
-type callback() :: module() | [module()].

一个回调模块或继承的回调模块列表。

-type element() :: xmlText() | xmlElement() | xmlPI() | xmlComment() | xmlDecl().

标准的、格式良好的 XML 内容元素。

链接到此类型

simple_attribute()

查看源代码 (未导出)
-type simple_attribute() :: xmlAttribute() | {fun((_) -> _), term()} | {Key :: atom(), Value :: term()}.

“简单形式”的 XML 属性。

链接到此类型

simple_element()

查看源代码 (未导出)
-type simple_element() ::
          {Tag :: atom(),
           Attributes :: [{Name :: atom(), Value :: iolist() | atom() | integer()}],
           Content :: [simple_element()]} |
          {Tag :: atom(), Content :: [simple_element()]} |
          (Tag :: atom() | (IOString :: iolist() | element())).

“简单形式”的 XML 内容元素。

-type xmlAttribute() ::
          #xmlAttribute{name :: term(),
                        expanded_name :: term(),
                        nsinfo :: term(),
                        namespace :: term(),
                        parents :: term(),
                        pos :: term(),
                        language :: term(),
                        value :: term(),
                        normalized :: term()}.

记录 #xmlAttribute{}

-type xmlComment() :: #xmlComment{parents :: term(), pos :: term(), language :: term(), value :: term()}.

记录 #xmlComment{}

-type xmlDecl() ::
          #xmlDecl{vsn :: term(), encoding :: term(), standalone :: term(), attributes :: term()}.

记录 #xmlDecl{}

-type xmlDocument() :: #xmlDocument{content :: term()}.

记录 #xmlDocument{}

-type xmlElement() ::
          #xmlElement{name :: term(),
                      expanded_name :: term(),
                      nsinfo :: term(),
                      namespace :: term(),
                      parents :: term(),
                      pos :: term(),
                      attributes :: term(),
                      content :: term(),
                      language :: term(),
                      xmlbase :: term(),
                      elementdef :: term()}.

记录 #xmlElement{}

-type xmlNamespace() :: #xmlNamespace{default :: term(), nodes :: term()}.

记录 #xmlNamespace{}

-type xmlNsNode() :: #xmlNsNode{parents :: term(), pos :: term(), prefix :: term(), uri :: term()}.

记录 #xmlNsNode{}

-type xmlPI() :: #xmlPI{name :: term(), parents :: term(), pos :: term(), value :: term()}.

记录 #xmlPI{}

-type xmlText() ::
          #xmlText{parents :: term(),
                   pos :: term(),
                   language :: term(),
                   value :: term(),
                   type :: term()}.

记录 #xmlText{}

函数

-spec callbacks(Module :: module()) -> [module()].

查找给定模块的继承回调模块列表。

链接到此函数

export(Content, Callback)

查看源代码
-spec export(Content :: term(), Callback :: term()) -> ExportedFormat :: term().

等同于 export(Content, Callback, [])

链接到此函数

export(Content, Callback, RootAttributes)

查看源代码
-spec export(Content, Callback, RootAttributes) -> ExportedFormat :: term()
                when
                    Content :: [Element],
                    Element :: element(),
                    Callback :: callback(),
                    RootAttributes :: [simple_attribute()].

导出 XML 内容。

使用指定的回调模块导出标准的、格式良好的 XML 内容。

Element 可以是以下任意一种:

  • #xmlText{}
  • #xmlElement{}
  • #xmlPI{}
  • #xmlComment{}
  • #xmlDecl{}

(有关记录定义,请参见 xmerl.hrl。)#xmlText{} 元素中的文本可以是字符和/或二进制的深层列表。

RootAttributes#root# 元素的 #xmlAttribute{} 属性列表,它隐式地成为给定 Content 的父元素。因此,#root# 的标签处理函数会使用 Content 的完整导出数据进行调用。根属性可以用来指定 XML 或 HTML 文档的编码或其他元数据。

Callback 模块应包含数据结构中出现的所有标签的钩子函数。钩子函数必须具有以下格式:

    Tag(Data, Attributes, Parents, E)

其中 E 是对应的 #xmlElement{}DataE 的已导出内容,AttributesE#xmlAttribute{} 记录列表。最后,ParentsE 的父节点列表,形式为 [{ParentTag::atom(), ParentPosition::integer()}]

钩子函数应返回要导出的数据,或者一个元组 {'#xml-alias#', NewTag::atom()},或者一个元组 {'#xml-redefine#', Content},其中 Content 是内容列表(可以是简单形式;有关详细信息,请参见 export_simple/2)。

回调模块可以通过所需的函数 '#xml-interitance#'() -> [ModuleName::atom()] 从其他回调模块继承定义。

另请参见: export/2export_simple/3

链接到此函数

export_content(Content, Callbacks)

查看源代码
-spec export_content(Content, Callbacks) -> _ when Content :: [element()], Callbacks :: [module()].

直接导出标准 XML 内容,无需进一步的上下文。

链接到此函数

export_element(Element, Callback)

查看源代码
-spec export_element(Element, Callback) -> _ when Element :: element(), Callback :: callback().

直接导出标准 XML 元素,无需进一步的上下文。

链接到此函数

export_element(Element, Callback, CallbackState)

查看源代码
-spec export_element(Element, Callback, CallbackState) -> ExportedFormat
                        when
                            Element :: element(),
                            Callback :: callback(),
                            CallbackState :: term(),
                            ExportedFormat :: term().

用于在 XML 文档解析(SAX 样式)期间进行动态导出。

链接到此函数

export_simple(Content, Callback)

查看源代码

等同于 export_simple(Content, Callback, [])

链接到此函数

export_simple(Content, Callback, RootAttributes)

查看源代码
-spec export_simple(Content, Callback, RootAttributes) -> ExportedFormat :: term()
                       when
                           Content :: [Element],
                           Element :: simple_element(),
                           Callback :: callback(),
                           RootAttributes :: [simple_attribute()].

导出“简单形式”的 XML 内容。

使用指定的回调模块导出“简单形式”的 XML 内容。

Element 可以是以下任意一种:

  • {Tag, Attributes, Content}
  • {Tag, Content}
  • Tag
  • IOString
  • #xmlText{}
  • #xmlElement{}
  • #xmlPI{}
  • #xmlComment{}
  • #xmlDecl{}

其中

  • Tag = atom()
  • Attributes = [{Name, Value}]
  • Name = atom()
  • Value = IOString | atom() | integer()

因此,标准形式的 XML 元素可以包含在简单形式的表示中。请注意,内容列表必须是扁平的。IOString 是字符和/或二进制的(可能很深的)列表。

RootAttributes 是列表:

  • XmlAttributes = #xmlAttribute{}

有关回调模块和根属性的详细信息,请参见 export/3。XML 数据在传递给回调模块之前始终会转换为标准形式。

另请参见: export/3export_simple/2

链接到此函数

export_simple_content(Content, Callback)

查看源代码
-spec export_simple_content(Content, Callback) -> _
                               when Content :: [simple_element()], Callback :: callback().

直接导出简单 XML 内容,无需进一步的上下文。

链接到此函数

export_simple_element(Element, Callback)

查看源代码
-spec export_simple_element(Element, Callback) -> _
                               when Element :: simple_element(), Callback :: callback().

直接导出简单的 XML 元素,无需进一步的上下文。