How to find out an OpenXml element is legit child for another

Ahmet Çiftci 6 Reputation points
2022-03-25T10:07:37.023+00:00

In older versions of OpenXml-sdk, every element has ChildInfoAttributes. So, it was enough to look at the list of ChildInfoAttribute to determine which types of elements it can accept as a child. Recent versions of OpenXml-Sdk removed this.

//Doesn't work in recent versions of OpenXml-Sdk
bool IsLegitChild(Type parent, Type children)
{
    var childInfos =
        (ChildElementInfoAttribute[]) Attribute.GetCustomAttributes(
            parent,
            typeof(ChildElementInfoAttribute));

    return childInfos.Any(x => x.ElementType == children);
}

How to implement this in recent versions of OpenXml-Sdk?

Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,653 questions
0 comments No comments
{count} vote