Expand Minimize
This topic has not yet been rated - Rate this topic

Bookmark.InsertXML Method

Inserts the specified XML text into the Bookmark control.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
void InsertXML(
	string XML,
	ref Object Transform
)

Parameters

XML
Type: String

The XML text to insert.

Transform
Type: Object

The transform to apply to the inserted XML text.

If the Bookmark control contains text, the InsertXML method replaces the existing text.

Calling this method might delete the Bookmark control.

Use the InsertXML method to insert text marked up with either arbitrary XML or Word XML. The XML must be well formed. If it uses Word XML, then it must also be valid according to the Word XML schema.

If the specified XML text cannot be inserted into the Bookmark control, an error message is displayed.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example adds a Bookmark control to the document and then inserts XML text into the bookmark. A message box is then displayed to show the total number of XMLNodes and the XML content of the bookmark.

This example is for a document-level customization.

private void BookmarkInsertXML()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "Sample of bookmark text.";

    bookmark1.Words[1].InsertXML("<example>This is an example.</example>",
        ref missing);

    MessageBox.Show("Total XMLNodes in bookmark1: " + bookmark1.XMLNodes.Count +
        "\n" + "XML contents: " + bookmark1.XML[true]);
}
Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.