All docs
V21.1
21.1
20.2
20.1
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

OfficeCustomXmlPart.CustomXmlPartDocument Property

Provides access to an XML document of the current custom XML part.

Namespace: DevExpress.Office

Assembly: DevExpress.Office.v21.1.Core.dll

Declaration

XmlDocument CustomXmlPartDocument { get; }

Property Value

Type Description
XmlDocument

An XML document.

Remarks

Use the CustomXmlPartDocument property to obtain and modify an XML document stored as a custom XML part in a workbook or text document.

Access a Custom XML Part of a DOCX Document

The example below shows how to retrieve employee names from a custom XML document stored in a DOCX file.

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Xml;
// ...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    Document document = wordProcessor.Document;
    // Load a document.
    document.LoadDocument("Documents\\CustomXmlParts.docx");
    // Access a custom XML file stored in the document.
    XmlDocument xmlDoc = document.CustomXmlParts[0].CustomXmlPartDocument;
    // Retrieve employee names from the XML file and display them in the document.
    XmlNodeList nameList = xmlDoc.GetElementsByTagName("Name");
    document.AppendText("Employee list:");
    foreach (XmlNode name in nameList)
    {
        document.AppendText("\r\n \u00B7 " + name.InnerText);
    }
}

Access a Custom XML Part of an XLSX Document

The example below shows how to use XPath to retrieve information from a workbook’s custom XML part.

using DevExpress.Spreadsheet;
using System.Xml;
// ...

using (Workbook workbook = new Workbook())
{
    // Load a document.
    workbook.LoadDocument("Documents\\CustomXml.xlsx");
    // Access a custom XML file stored in the document.
    XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
    // Retrieve a reference to a fish that belongs to a specific category.
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
    string xPathString = "//Fish[Category='Cod']/ScientificClassification/Reference";
    XmlNode xmlNode = xmlDoc.DocumentElement.SelectSingleNode(xPathString, nsmgr);
    string hLink = xmlNode.InnerText;
    // Display the obtained value in a cell as a hyperlink.
    workbook.Worksheets[0].Hyperlinks.Add(workbook.Worksheets[0].Cells["A2"], hLink, true);
}
See Also