Skip to main content

OfficeCustomXmlPart.CustomXmlPartDocument Property

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

Namespace: DevExpress.Office

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

NuGet Packages: DevExpress.Office.Core, DevExpress.Win.Navigation

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.

View Example

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);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomXmlPartDocument property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also