Open-XML-SDK icon indicating copy to clipboard operation
Open-XML-SDK copied to clipboard

`TextMath` object drops child elements when clone

Open wreulicke opened this issue 3 years ago • 3 comments

Description

TextMath object drops child elements when clone. I am not sure that this problem occurs in the case of other elements.

Information

  • .NET Target: (ie .NET Framework, .NET Core, UWP, Xamarin, etc)
    • .Net Core 5.0.400
  • DocumentFormat.OpenXml Version: 2.13.1

Repro

DocumentFormat.OpenXml.Office2010.Drawing.TextMath original = ...;
DocumentFormat.OpenXml.Office2010.Drawing.TextMath clone = original.CloneNode(true);

Console.WriteLine(original.OuterXml) ;
// output:
//  <a14:m xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main">
//    <m:oMathPara xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
//    ...
//  </a14m>
Console.WriteLine(clone.OuterXml) ;
// output:
//  <a14:m xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" />

Observed

TextMath drops child elements when clone slide object.

Expected

TextMath has child elements

wreulicke avatar Sep 30 '21 06:09 wreulicke

@wreulicke Thanks for reporting this. I've verified this in code and am investigating.

tomjebo avatar Sep 30 '21 23:09 tomjebo

@wreulicke looks like the problem is that the TextMath class defined in ...src\DocumentFormat.OpenXml\GeneratedCode\schemas_microsoft_com_office_drawing_2010_main.g.cs does not contain the required metadata (ConfigureMetadata) to declare valid children and therefore when the DOM is read in, TextMath has no children even before cloning. This is something I'll have to investigate on our backend generator. I think it will be possible to add but will update here after further investigation. There may be other types that have this issue as well. It's possible that because the children are VML:

<m:oMathPara xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">

types, the code generator left that out. UPDATE: I took a quick look at the backend and it left out the possible children in the xsd. This is very old and it looks like it was intentional. I will give it a stab and see if I can add the VML math types as children to the a14:math class. They (m:oMathPara and friends) were generated as types in the SDK so at least that is good news.

tomjebo avatar Oct 05 '21 01:10 tomjebo

@tomjebo Thanks!

wreulicke avatar Oct 15 '21 07:10 wreulicke