Back to Devexpress

OfficeCustomXmlPart.CustomXmlPartDocument Property

officefileapi-devexpress-dot-office-dot-officecustomxmlpart.md

latest10.4 KB
Original Source

OfficeCustomXmlPart.CustomXmlPartDocument Property

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

Declaration

csharp
XmlDocument CustomXmlPartDocument { get; }
vb
ReadOnly Property CustomXmlPartDocument As XmlDocument

Property Value

TypeDescription
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.

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

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

csharp
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);
}
vb
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.

winforms-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/CodeExamples/CustomXmlPartActions.cs#L46

csharp
workbook.LoadDocument("Documents\\CustomXml.xlsx");
XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/CustomXmlPartActions.cs#L51

csharp
workbook.LoadDocument("Documents\\CustomXml.xlsx");
XmlDocument xmlDoc = workbook.CustomXmlParts[0].CustomXmlPartDocument;
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/CustomXmlPartActions.cs#L56

csharp
// 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

csharp
// 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

csharp
// 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.

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/CustomXmlPartActions.vb#L41

vb
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)

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/CustomXmlPartActions.vb#L52

vb
' 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

vb
' 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

vb
' 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

vb
' 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

OfficeCustomXmlPart Interface

OfficeCustomXmlPart Members

DevExpress.Office Namespace