跳到主要内容

SetText

设置当前 XML 节点的文本内容。

语法

expression.SetText(str);

expression - 表示 ApiCustomXmlNode 类的变量。

参数

名称必需/可选数据类型默认值描述
str必需string要设置给节点的文本内容。

返回值

boolean

示例

此示例演示如何获取自定义 XML 节点的 XPath。

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xmlText = `
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book>
<title lang="en">The Odyssey</title>
<author>Homer</author>
<year>-740</year>
<price>30.00</price>
</book>
</bookstore>`;
let xml = xmlManager.Add(xmlText);
let node = xml.GetNodes('/bookstore/book/title')[0];
node.SetText('Iliad');
node = xml.GetNodes('/bookstore/book/year')[0];
node.SetText('9th–8th centuries BC');
let paragraph = Api.CreateParagraph();
paragraph.AddText("\r\nContent of custom xml:\r\n");
paragraph.AddText(xml.GetXml());
doc.AddElement(0, paragraph);