dotnet / Open-XML-SDK

Open XML SDK by Microsoft
https://www.nuget.org/packages/DocumentFormat.OpenXml/
MIT License
4.02k stars 546 forks source link

Found OpenXmlUnknownElement instead of CommentPropertiesExtension #1751

Closed tomjebo closed 3 months ago

tomjebo commented 3 months ago

Describe the bug

In part \ppt\comment\modernComment... part is coded in the SDK metadata as p188:ext. This causes OpenXmlUnknownElement to be assigned as the child of p188:extLst.
       <p188:extLst>
            <p:ext xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" uri="{5BB2D875-25FF-4072-B9AC-8F64D62656EB}">
                <p228:taskDetails xmlns:p228="http://schemas.microsoft.com/office/powerpoint/2022/08/main">
                    <p228:history>
                        <p228:event time="2024-07-16T05:56:24.928" id="{22A90AAB-29DC-4F45-80B8-41660EB3CE91}">
                            <p228:atrbtn authorId="{DDBD2B34-3E97-38F7-B7A9-5BD8D52D7288}"/>
                            <p228:anchr>
                                <p228:comment id="{C5BB4569-00FC-429B-B44C-282847B06E34}"/>
                            </p228:anchr>
                            <p228:add/>

This should be fixed on our schema processor.

To Reproduce Create a presentation with a modern comment. Then inspect the \ppt\comment\modernCommentXXXX.xml part. The above shows p:ext and that is per the Office schemas.

However, when parsing in SDK code:

    SlidePart sp = pd.PresentationPart.GetPartsOfType<SlidePart>().First();

    PowerPointCommentPart ppcp = sp.GetPartsOfType<PowerPointCommentPart>().First();

    if (ppcp.RootElement is null)
    {
        throw new InvalidDataException("no root element!");
    }

    CommentPropertiesExtensionList cpel = ppcp.RootElement.Descendants<CommentPropertiesExtensionList>().First();

    if (cpel is null)
    {
        throw new InvalidDataException("Presentation modern comment part is missing p188:extlst");
    }

    CommentPropertiesExtension cpe = cpel.ChildElements.First<CommentPropertiesExtension>();

    if (cpe is null)
    {
// This line will throw because cpe is null due to the p:ext being wrapped by OpenXmlUnknownElement. 
// In our patched schemas we code this as p188:ext which is wrong. 
        throw new InvalidDataException("Presentation modern comment part is missing p188:ext");
    }

Steps to reproduce the behavior: Use the code above to access the ext child element the extLst in a p188:cm block.

Observed behavior cpe is null.

Expected behavior In the code above, cpe should be a valid CommentPropertiesExtension object wrapping the p:ext.

Desktop (please complete the following information):