We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Manipulation of CustomXML with Aspose.Slides (C# .NET)

Hi Aspose team,

does Aspose.Slides support reading and editing of customXML in PowerPoint documents? If yes, do you have sample code?

Thanks,
Oliver

@dr.doc,

The CustomXML is supported in Aspose.Slides and you can add, remove or access the CustomXML inside slide.

The following sample can be used to remove the CustomXML from slides.

//Sample for clear all custom xml parts from presentation
using (Presentation pres = new Presentation("PresentationWithCustomXml.pptx"))
{
    foreach (ICustomXmlPart item in pres.AllCustomXmlParts)
    {
        item.Remove();
    }
    pres.Save("out.pptx", SaveFormat.Pptx);
}

Property Aspose.Slides.ICustomData.CustomXmlParts has been added. It represents a collection of custom xml parts associated with the corresponding ICustomData instance.

using(Presentation pres = new Presentation())
{
    pres.Slides[0].CustomData.CustomXmlParts.Add(GetXmlStringSample("John Doe")); //add new custom xml to slide custom data
    pres.Save(@"out.pptx", SaveFormat.Pptx);
}

private static string GetXmlStringSample(string name)
{
    string xmlString =
        "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<employees xmlns=\"http://schemas.test.com/sample\">" +
            "<employee>" +
                "<name>" + name + "</name>" +
            "</employee>" +
        "</employees>";
    return xmlString;
}

Thanks, this worked :slight_smile:

@dr.doc,

It’s good to know that suggested sample has worked on your end.

One other question - how can I change existing customXML.
When I try:
string oldPart = item.XmlAsString;
oldPart = oldPart.Replace(“DocumentLibraryForm”, “Aspose”);
item.XmlAsString = oldPart;

and then save document, it is corrupted.
Basically, I need to read XML of customPart, make changes of it and replace old XML with updated XML.

Thx

@dr.doc,

I would request you to please share the working sample code along with source presentation and generated presentation that is corrupt as we may need to investigate this issue further and log that in our issue tracking system.

Sure, please check attached project.
In Powerpoint folder you have original customParts.pptx and changed customPartsUpdated.pptx.

BR,
Oliver

Slides.CustomParts.zip (226.4 KB)

@dr.doc,

It seems to be an issue with API while modifying the CustomXML data for your presentation. A ticket with ID SLIDESNET-42010 has been created to further investigate and resolve the issue. We will share the good news with you as soon as it will be fixed.

The issues you have found earlier (filed as SLIDESNET-42010) have been fixed in this update.