跳到主要内容

DeleteElement

删除指定 XPath 的 XML 元素。

语法

expression.DeleteElement(xPath);

expression - 表示 ApiCustomXmlPart 类的变量。

参数

名称必需/可选数据类型默认值描述
xPath必需string要删除的节点的 XPath。

返回值

boolean

示例

从文档中的自定义 XML 部件中删除 XML 元素。

// How do I delete the element in a document?

// Delete the element using a custom XML part object in a document.

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xml = xmlManager.Add("<content xmlns='http://example'><text>example_text</text><firstNode>text inside first node</firstNode></content>");
xml.DeleteElement("/content/firstNode");
let infoParagraph = Api.CreateParagraph();
infoParagraph.AddText("Xml string representation after deletion: " + xml.GetXml());
doc.Push(infoParagraph);