Word) (Range.InsertXML 方法

将指定的 XML 插入文档中的指定区域,并且替换该区域中包含的任何文本。

语法

表达式InsertXML (XML转换)

expression:一个返回 Range 对象的表达式。

参数

名称 必需/可选 数据类型 说明
XML 必需 String 指定要插入的 XML。 这可以是任何有效的自定义 XML。
Transform 可选 Variant 指定用于转换 XML 的 XML 转换 (XSLT)。 如果省略,则将 XML 作为自定义 XML 插入,而不应用转换。

返回值

示例

以下示例将指定的 XML 字符串插入文档中的第五段。 这将替换第五段中包含的任何文本。

Dim strXML As String 
 
strXML = "<"xml version=""1.0""><abc:books xmlns:abc=""urn:books"" " & _ 
 "xmlns:xsi=""https://www.w3.org/2001/XMLSchema-instance"" " & _ 
 "xsi:schemaLocation=""urn:books books.xsd""><book>" & _ 
 "<author>Matt Hink</author><title>Migration Paths of the Red " & _ 
 "Breasted Robin</title><genre>non-fiction</genre>" & _ 
 "<price>29.95</price><pub_date>2006-05-01</pub_date>" & _ 
 "<abstract>You see them in the spring outside your windows. " & _ 
 "You hear their lovely songs wafting in the warm spring air. " & _ 
 "Now follow their path as they migrate to warmer climes in the fall, " & _ 
 "and then back to your back yard in the spring.</abstract></book></abc:books>" 
 
ActiveDocument.Paragraphs(5).Range.InsertXML strXML

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。