DeleteElement
删除指定 XPath 的 XML 元素。
语法
expression.DeleteElement(xPath);
expression - 表示 ApiCustomXmlPart 类的变量。
参数
| 名称 | 必需/可选 | 数据类型 | 默认值 | 描述 |
|---|---|---|---|---|
| xPath | 必需 | string | 要删除的节点的 XPath。 |
返回值
boolean
示例
从文档中嵌入的结构化数据移除 XML 元素。
// How do I delete a specific element from the XML data stored in a document?
// Trim unnecessary child nodes from structured content to keep the stored data lean 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);