目录

类

class XmlAttr

public class XmlAttr <: ToString {
    public init(name: String, content: String)
}

功能:此类存储 XML 元素节点属性,并提供查询其内容的函数。

部分接口提供了有限的检查功能,例如节点名称为空,首字母为 '-' 、 '.' 、 '[0-9]' 等。

如需使用 XmlAttr 构造 XML 文档,请注意符合 XML 规范,具体规范请查阅 W3C 官网。

[h2]prop content

public mut prop content: String

功能:获取或设置属性值。

类型:String

[h2]prop name

public mut prop name: String

功能:获取或设置属性名称。

类型:String

异常:

[h2]init(String, String)

public init(name: String, content: String)

功能:创建一个 XmlAttr 对象。

参数:

异常:

[h2]func toString()

public func toString(): String

功能:将 XmlAttr 转换成字符串。

返回值:

class XmlElement

public class XmlElement <: ToString {
    public init(name: String, content: String)
}

功能:此类存储 XML 元素节点,并提供查询其内容的函数。

部分接口提供了有限的检查功能,例如节点名称为空,首字母为 '-' 、 '.' 、 '[0-9]',属性名称必须保证唯一等。

如需使用 XmlELement 构造 XML 文档,请注意符合 XML 规范,具体规范请查阅 W3C 官网。

[h2]prop attributes

public mut prop attributes: ArrayList<XmlAttr>

功能:获取节点的属性,返回节点属性的深拷贝,设置节点的属性。

类型:ArrayList<XmlAttr>

异常:

[h2]prop attributesNum

public prop attributesNum: Int64

功能:获取节点的属性个数。

类型:Int64

[h2]prop childrenElements

public mut prop childrenElements: ArrayList<XmlElement>

功能:获取或设置节点的所有子节点。

类型:ArrayList<XmlElement>

[h2]prop childrenNum

public prop childrenNum: Int64

功能:获取节点的子节点个数。

类型:Int64

[h2]prop content

public mut prop content: String

功能:获取或设置节点文本内容。

类型:String

[h2]prop isClosed

public prop isClosed: Bool

功能:判断节点是否闭合。

类型:Bool

[h2]prop name

public mut prop name: String

功能:获取或设置节点名称。

类型:String

异常:

[h2]init(String, String)

public init(name: String, content: String)

功能:创建一个 XmlElement 对象。

参数:

异常:

[h2]func toString()

public func toString(): String

功能:返回 XML 字符串,该字符串会在一行显示,其中的实体引用将会被解析,例如: '&lt;' 将替换成 '<'。

返回值:

[h2]func toXmlString()

public func toXmlString(): String

功能:返回格式化后的 XML 字符串,该字符串会以 XML 的格式体现,其中的实体引用将会被解析,例如: '&lt;' 将替换成 '<'。

返回值:

class XmlParser

public class XmlParser {
    public init()
    public init(handler: SaxHandler)
}

功能:此类提供 XML 解析功能。

目前支持两种模式:文档对象模型(DOM)模式和 XML 简单 API(SAX)模式,暂不支持外部实体功能,以及 <? ?> 形式的指令声明。

支持 5 个内置符号的解析,如下表所示:

符号 字符
< &lt;, &#60;, &#x3c;
> &gt;, &#62;, &#x3e;
& &amp;, &#38;, &#x26;
' &apos;, &#39;, &#x27;
" &quot;, &#34;, &#x22;

[h2]init()

public init()

功能:创建 XML 文档对象模型(DOM)模式解析器。

异常:

[h2]init(SaxHandler)

public init(handler: SaxHandler)

功能:创建 XML 简单 API(SAX)模式解析器。

参数:

异常:

[h2]func parse(String)

public func parse(str: String): Option<XmlElement>

功能:解析字符串类型的 XML 文本。

参数:

返回值:

异常: