跳到主要内容

GetById

根据 ID 从 XML 管理器返回自定义 XML 部件。

语法

expression.GetById(xmlPartId);

expression - 表示 ApiCustomXmlParts 类的变量。

参数

名称必需/可选数据类型默认值描述
xmlPartId必需stringXML 部件 ID。

返回值

ApiCustomXmlPart | null

示例

此示例演示如何根据命名空间检索自定义 XML 部件。

let doc = Api.GetDocument();
let xmlManager = doc.GetCustomXmlParts();
let xmlText = "<content xmlns='http://example.com'><text>Example XML</text></content>";
let xml = xmlManager.Add(xmlText);
let namespace = "http://example.com";
let xmlParts = xmlManager.GetByNamespace(namespace);
let infoParagraph = Api.CreateParagraph();
xmlParts.forEach(part => {
infoParagraph.AddText("XML part: " + part.GetXml());
});
doc.Push(infoParagraph);