officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-f9e782fb.md
Provides access to a document’s collection of custom XML parts.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
CustomXmlPartCollection CustomXmlParts { get; }
ReadOnly Property CustomXmlParts As CustomXmlPartCollection
| Type | Description |
|---|---|
| CustomXmlPartCollection |
A collection of custom XML parts.
|
You can embed arbitrary XML data (called custom XML parts) in documents in DOCX and DOC format. Custom XML parts are included in the document structure but are not visible in the document.
The image below shows the structure of a DOCX file with three custom XML parts (item1, item2, and item3).
The Document.CustomXmlParts property provides access to the CustomXmlPartCollection collection that stores custom XML parts. Use the collection’s members to insert, obtain, modify, or remove custom XML parts.
The example below shows how to add custom XML parts to a document.
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Xml;
// ...
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
Document document = wordProcessor.Document;
document.AppendText("This document contains custom XML parts.");
// Add an empty custom XML part.
ICustomXmlPart xmlItem = document.CustomXmlParts.Add();
// Populate the XML part with content.
XmlElement elem = xmlItem.CustomXmlPartDocument.CreateElement("Employees");
elem.InnerText = "Stephen Edwards";
xmlItem.CustomXmlPartDocument.AppendChild(elem);
// Use a string to specify the content for a custom XML part.
string xmlString = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Employees>
<FirstName>Stephen</FirstName>
<LastName>Edwards</LastName>
<Address>4726 - 11th Ave. N.E.</Address>
<City>Seattle</City>
<Region>WA</Region>
<PostalCode>98122</PostalCode>
<Country>USA</Country>
</Employees>";
document.CustomXmlParts.Insert(1, xmlString);
// Add a custom XML part from a file.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Documents\\Employees.xml");
document.CustomXmlParts.Add(xmlDoc);
document.SaveDocument("Documents\\CustomXmlTestDoc.docx", DocumentFormat.Docx);
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Xml
' ...
Using wordProcessor As New RichEditDocumentServer()
Dim document As Document = wordProcessor.Document
document.AppendText("This document contains custom XML parts.")
' Add an empty custom XML part.
Dim xmlItem As ICustomXmlPart = document.CustomXmlParts.Add()
' Populate the XML part with content.
Dim elem As XmlElement = xmlItem.CustomXmlPartDocument.CreateElement("Employees")
elem.InnerText = "Stephen Edwards"
xmlItem.CustomXmlPartDocument.AppendChild(elem)
' Use a string to specify the content for a custom XML part.
Dim xmlString As String = "<?xml version=""1.0"" encoding=""UTF-8""?>
<Employees>
<FirstName>Stephen</FirstName>
<LastName>Edwards</LastName>
<Address>4726 - 11th Ave. N.E.</Address>
<City>Seattle</City>
<Region>WA</Region>
<PostalCode>98122</PostalCode>
<Country>USA</Country>
</Employees>"
document.CustomXmlParts.Insert(1, xmlString)
' Add a custom XML part from a file.
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("Documents\Employees.xml")
document.CustomXmlParts.Add(xmlDoc)
document.SaveDocument("Documents\CustomXmlTestDoc.docx", DocumentFormat.Docx)
End Using
See Also