/// <summary> /// Trys to create an OpenXmlElement from the specified namespace URI and local name. /// </summary> /// <param name="parent">The parent element.</param> /// <param name="fileFormat">The specified file format version.</param> /// <param name="namespaceUri">The namespace URI of the requested child element.</param> /// <param name="localName">The local name of the requested child element.</param> /// <returns>A new OpenXmlElement if the parent element can contains a child with the specified namespace and local name. Otherwise, returns null.</returns> internal static OpenXmlElement?TryCreateValidChild(this OpenXmlElement parent, FileFormatVersions fileFormat, string namespaceUri, string localName) { Debug.Assert(parent is OpenXmlCompositeElement); var newElement = parent.CreateElement(OpenXmlQualifiedName.Create(namespaceUri, string.Empty, localName)); if (newElement is OpenXmlUnknownElement || !newElement.IsInVersion(fileFormat)) { return(null); } return(newElement); }