Back to Devexpress

OfficeCustomXmlPartCollection<T>.Clear() Method

officefileapi-devexpress-dot-office-dot-officecustomxmlpartcollection-1.md

latest3.9 KB
Original Source

OfficeCustomXmlPartCollection<T>.Clear() Method

Removes all custom XML parts from the collection.

Namespace : DevExpress.Office

Assembly : DevExpress.Office.v25.2.Core.dll

NuGet Package : DevExpress.Office.Core

Declaration

csharp
void Clear()
vb
Sub Clear

Remarks

Use the Remove or RemoveAt method to remove a specific custom XML part from CustomXmlPartCollection associated with a text document or workbook.

The example below shows how to remove custom XML parts from a DOCX file.

csharp
using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    Document document = wordProcessor.Document;
    document.AppendText("This document contains custom XML parts.");

    // Add the first custom XML part.
    string xmlString1 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
                            <Employees>
                                <FirstName>Stephen</FirstName>
                                <LastName>Edwards</LastName>
                            </Employees>";
    var xmlItem1 = document.CustomXmlParts.Add(xmlString1);

    // Add the second custom XML part.
    string xmlString2 = @"<?xml version=""1.0"" encoding=""UTF-8""?>
                            <Employees>
                                <FirstName>Andrew</FirstName>
                                <LastName>Fuller</LastName>
                            </Employees>";
    var xmlItem2 = document.CustomXmlParts.Add(xmlString2);

    // Remove the first item from the collection.
    document.CustomXmlParts.Remove(xmlItem1);
    // Use the RemoveAt method to remove an item at the specified position from the collection.
    // document.CustomXmlParts.RemoveAt(0);
    // Use the Clear method to remove all items from the collection.
    // document.CustomXmlParts.Clear();
}
vb
Using wordProcessor As New RichEditDocumentServer()
    Dim document As Document = wordProcessor.Document
    document.AppendText("This document contains custom XML parts.")

    ' Add the first custom XML part.
    Dim xmlString1 As String = "<?xml version=""1.0"" encoding=""UTF-8""?>
                            <Employees>
                                <FirstName>Stephen</FirstName>
                                <LastName>Edwards</LastName>
                            </Employees>"
    Dim xmlItem1 = document.CustomXmlParts.Add(xmlString1)

    ' Add the second custom XML part.
    Dim xmlString2 As String = "<?xml version=""1.0"" encoding=""UTF-8""?>
                            <Employees>
                                <FirstName>Andrew</FirstName>
                                <LastName>Fuller</LastName>
                            </Employees>"
    Dim xmlItem2 = document.CustomXmlParts.Add(xmlString2)

    ' Remove the first item from the collection.
    document.CustomXmlParts.Remove(xmlItem1)
    ' Use the RemoveAt method to remove an item at the specified position from the collection.
    ' document.CustomXmlParts.RemoveAt(0)
    ' Use the Clear method to remove all items from the collection.
    ' document.CustomXmlParts.Clear()
End Using

See Also

OfficeCustomXmlPartCollection<T> Interface

OfficeCustomXmlPartCollection<T> Members

DevExpress.Office Namespace