Share via


DocumentBase.CustomXMLParts Property

Returns the custom XML parts in the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Syntax

'Declaration
Public ReadOnly Property CustomXMLParts As CustomXMLParts
public CustomXMLParts CustomXMLParts { get; }

Property Value

Type: CustomXMLParts
A Microsoft.Office.Core.CustomXMLParts collection that contains the custom XML parts in the document.

Remarks

For more information about using custom XML parts in Office projects, see Custom XML Parts Overview.

Examples

The following code example embeds employee data in the document by adding a Microsoft.Office.Core.CustomXMLPart to the CustomXMLParts collection in the current document. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub AddCustomXmlPartToDocument()
    Dim xmlString As String = _
        "<?xml version=""1.0"" encoding=""utf-8"" ?>" & _
            "<employees https://schemas.microsoft.com/vsto/samples"">" & _
                "<employee>" & _
                    "<name>Karina Leal</name>" & _
                    "<hireDate>1999-04-01</hireDate>" & _
                    "<title>Manager</title>" & _
                "</employee>" & _
            "</employees>" 

    Dim employeeXMLPart As Office.CustomXMLPart = _
        Me.CustomXMLParts.Add(xmlString)
End Sub
private void AddCustomXmlPartToDocument()
{
    string xmlString =
        "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
        "<employees xmlns=\"https://schemas.microsoft.com/vsto/samples\">" +
            "<employee>" +
                "<name>Karina Leal</name>" +
                "<hireDate>1999-04-01</hireDate>" +
                "<title>Manager</title>" +
            "</employee>" +
        "</employees>";

    Office.CustomXMLPart employeeXMLPart = this.CustomXMLParts.Add(xmlString, missing);
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace

Other Resources

Custom XML Parts Overview