XML_SET 系列¶
函数名 | 参数 | 返回值 |
---|---|---|
![]() XML_SET | int , string , string (, int , int ) | int |
ref string , string , string (, int , int ) | int | |
![]() XML_SET_BYNAME | string , string , string (, int , int ) | int |
API
1. int XML_SET xmlId, xpath, value(, doSetAll, outputType)
2. int XML_SET ref xml, xpath, value(, doSetAll, outputType)
3. int XML_SET_BYNAME xmlName, xpath, value(, doSetAll, outputType)
XML
中将 xpath
选择的节点(详见 XPath
的介绍)内容设为 value
。当 xpath
的匹配结果存在多个时,必须将参数 doSetAll
设为 0
以外的数值才能成功更新节点。更新节点成功时,返回已更新节点的数量;失败时返回 0
。 - 从以
xmlId
的字符串转换结果(TOSTR
)为 ID 而指定的XmlDocument
中检索元素节点进行更新。若指定的XmlDocument
不存在,返回-1
。 - 从指定的
xml
内容中检索元素节点进行更新,并将新的结果重新赋值给xml
;xml
必须是变量。 - 从以
xmlName
为 ID 而指定的XmlDocument
中检索元素节点进行更新。若指定的XmlDocument
不存在,返回-1
。
根据参数 outputType
的值决定返回结果的类型:
1
: 节点的InnerText
2
: 节点的InnerXml
- 其他值或直接省略: 节点的
Value
注意
获取的 XML 不是真正的 XmlNode
节点实例,因此在 xpath
的开头使用「//
」快捷表示方法并不会生效。
提示
命令 / 行内函数两种写法均有效。
示例代码
MAIN.ERB
@SYSTEM_TITLE
#DIMS xml = "<test><file name='A.txt'>InnerText内容A</file><a>A</a></test>"
; 直接从字符串中检索节点
PRINTFORML 匹配结果数量:{XML_SET(xml, "/test/*", "B", 1, 1)}
PRINTSL xml
XML_DOCUMENT 0, xml
; 从 XmlDocument 中检索节点
PRINTFORML 匹配结果数量:{XML_SET(0, "/test/file/@name", "X.xml")}
XML_GET 0, "/test/file/@name", 1
PRINTSL RESULTS
ONEINPUT
输出结果
匹配结果数量:2
<test><file name="A.txt">B</file><a>B</a></test>
匹配结果数量:1
X.xml