officefileapi-devexpress-dot-office-dot-officecustomxmlpart.md
Provides access to an XML document of the current custom XML part.
Namespace : DevExpress.Office
Assembly : DevExpress.Office.v25.2.Core.dll
NuGet Package : DevExpress.Office.Core
XmlDocument CustomXmlPartDocument { get; }
ReadOnly Property CustomXmlPartDocument As XmlDocument
| Type | Description |
|---|---|
| XmlDocument |
An XML document.
|
Use the CustomXmlPartDocument property to obtain and modify an XML document stored as a custom XML part in a workbook or text 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);
}
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Xml
' ...
Using wordProcessor As New RichEditDocumentServer()
Dim document As Document = wordProcessor.Document
' Load a document.
document.LoadDocument("Documents\CustomXmlParts.docx")
' Access a custom XML file stored in the document.
Dim xmlDoc As XmlDocument = document.CustomXmlParts(0).CustomXmlPartDocument
' Retrieve employee names from the XML file and display them in the document.
Dim nameList As XmlNodeList = xmlDoc.GetElementsByTagName("Name")
document.AppendText("Employee list:")
For Each name As XmlNode In nameList
document.AppendText(ControlChars.CrLf & " " & ChrW(&H00B7).ToString() & " " & name.InnerText)
Next name
End Using
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);
}
Imports DevExpress.Spreadsheet
Imports System.Xml
' ...
Using workbook As New Workbook()
' Load a document.
workbook.LoadDocument("Documents\CustomXml.xlsx")
' Access a custom XML file stored in the document.
Dim xmlDoc As XmlDocument = workbook.CustomXmlParts(0).CustomXmlPartDocument
' Retrieve a reference to a fish that belongs to a specific category.
Dim nsmgr As New XmlNamespaceManager(xmlDoc.NameTable)
Dim xPathString As String = "//Fish[Category='Cod']/ScientificClassification/Reference"
Dim xmlNode As XmlNode = xmlDoc.DocumentElement.SelectSingleNode(xPathString, nsmgr)
Dim hLink As String = xmlNode.InnerText
' Display the obtained value in a cell as a hyperlink.
workbook.Worksheets(0).Hyperlinks.Add(workbook.Worksheets(0).Cells("A2"), hLink, True)
End Using
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.
workbook.LoadDocument("Documents\\CustomXml.xlsx");
XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
workbook.LoadDocument("Documents\\CustomXml.xlsx");
XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
// Access a custom XML file stored in the document.
XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/CustomXmlParts.cs#L53
// 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.
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/CustomXmlActions.cs#L48
// 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.
workbook.LoadDocument("Documents\CustomXml.xlsx")
Dim xmlDoc As System.Xml.XmlDocument = workbook.CustomXmlParts(CInt((0))).CustomXmlPartDocument
Dim nsmgr As System.Xml.XmlNamespaceManager = New System.Xml.XmlNamespaceManager(xmlDoc.NameTable)
' Access a custom XML file stored in the document.
Dim xmlDoc As XmlDocument = workbook.CustomXmlParts(0).CustomXmlPartDocument
winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/CustomXmlParts.vb#L49
' Access a custom XML file stored in the document.
Dim xmlDoc As System.Xml.XmlDocument = document.CustomXmlParts(CInt((0))).CustomXmlPartDocument
' Retrieve employee names from the XML file and display them in the document.
wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/CustomXmlActions.vb#L44
' Access a custom XML file stored in the document.
Dim xmlDoc As XmlDocument = document.CustomXmlParts(0).CustomXmlPartDocument
' Retrieve employee names from the XML file and display them in the document.
word-document-api-examples/VB/CodeExamples/CustomXmlActions.vb#L59
' Access a custom XML file stored in the document.
Dim xmlDoc As System.Xml.XmlDocument = document.CustomXmlParts(CInt((0))).CustomXmlPartDocument
' Retrieve employee names from the XML file and display them in the document.
See Also