API
Class

Xml ($UI/system/lib/base/xml)

使用范围:UI2

Contents

class Xml ($UI/system/lib/base/xml)

XML工具类

Constructor Top

  Xml ()

Static Methods Top

Object eval (Node context, String xpathExp, String resultType, String namespaces)
Object eval2 (Node context, String xpathExp, String resultType, String namespaces)
Document fromString (String xmlStr)
Node getChildByName (Node context, String name)
String getNodeText (Node context, String xpathExp, String defaultValue)
Integer insertNodes (Node context, String xpathExp, List nodes, Boolean isBefore)
void removeNodes (Node context, String xpathExp)
Integer replaceNodes (Node context, String xpathExp, List nodes)
void setNodeText (Node context, String xpathExp, String text)
String toString (Node xmlNode)

Constructor details Top

public Xml ()

XML工具类

Static Methods Detail Top

static public Object eval (Node context, String xpathExp, String resultType, String namespaces)

在指定的节点上执行XPath, 返回相应的节点

Parameters

Node context

指定的XML节点

String xpathExp

XPath表达式

String resultType

标识返回单个节点或多个节点,取值范围{"single", "array"}

String namespaces

命名空间

Return Value

Object

static public Object eval2 (Node context, String xpathExp, String resultType, String namespaces)

在指定的节点上执行XPath, 返回相应的节点(简化版本)

Parameters

Node context

指定的XML节点

String xpathExp

XPath表达式

String resultType

标识返回单个节点或多个节点,取值范围{"single"}

String namespaces

命名空间

Return Value

Object

static public Document fromString (String xmlStr)

将String格式的XML转换成XML对象

Parameters

String xmlStr

Return Value

Document

static public Node getChildByName (Node context, String name)

根据tagName获取子节点

Parameters

Node context

指定的XML节点

String name

子节点的tagName

Return Value

Node

static public String getNodeText (Node context, String xpathExp, String defaultValue)

获取节点文本内容, 如果节点存在,返回指定的默认值

Parameters

Node context

指定的XML节点

String xpathExp

指定的节点的XPath

String defaultValue

默认值

Return Value

String

static public Integer insertNodes (Node context, String xpathExp, List nodes, Boolean isBefore)

插入节点

Parameters

Node context

指定的XML节点

String xpathExp

插入位置的XPath表达式

List nodes

待插入的节点列表

Boolean isBefore

是否插入到指定位置之前

Return Value

Integer

插入节点位置个数(就是xpathExp计算出的个数)

static public void removeNodes (Node context, String xpathExp)

删除节点

Parameters

Node context

指定的XML节点

String xpathExp

被删除节点的XPath

Return Value

void

static public Integer replaceNodes (Node context, String xpathExp, List nodes)

替换节点

Parameters

Node context

指定的XML节点

String xpathExp

被替换节点的XPath表达式

List nodes

待插入的节点列表

Return Value

Integer

被替换节点的个数

static public void setNodeText (Node context, String xpathExp, String text)

设置节点文本内容

Parameters

Node context

指定的XML节点

String xpathExp

指定节点的XPath

String text

Return Value

void

static public String toString (Node xmlNode)

将XML对象转换成String格式

Parameters

Node xmlNode

Return Value

String