3

I know how to convert an OpenXmlElement to outer xml by using the OpenXmlElement.OuterXml function but is it possible to do the opposite without knowing what kind of OpenXmlElement it's going to be?

For example I have the outerXml of a table, paragraph and run. Then is it possible to do something like:

new OpenXmlElement(unknownXml)

I saw the constructor of the OpenXmlElement is kept protected.

I'm not asking for any dirty switch statements or something like that.

---------------- Edit ------------------

I have come up with my own solution. I've created a library that does the conversion without using a dirty switch statement :-)

The library can be found here: https://github.com/LucBos/OpenXmlFactory

The usage of the library is described here: http://www.lucbos.net/2012/01/reconstructing-openxml-element-from-xml.html

4

1 に答える 1

0

から新しい にOpenXmlElementストリームを読み込むことで、ジェネリックを作成できます。ただし、適切な型を取得するクリーンな方法はありません。XElementOpenXmlElement

于 2011-12-23T14:57:34.770 に答える