You can convert a given OpenXmlElement to a XElement using the following code:

   1 OpenXmlElement el = ...; // Code to get the xml element from your office doc.
   2 
   3 // Then use XElement.Parse and the OuterXml property.
   4 XElement xel = XElement.Parse(el.OuterXml);

To convert an XElement to an OpenXmlElement try the following code:

   1 XElement xe = ...;
   2 using(StreamWriter sw = new StreamWriter(new MemoryStream()))
   3 {
   4   sw.Write(xe.ToString());
   5   sw.Flush();
   6   sw.BaseStream.Seek(0, SeekOrigin.Begin);
   7 
   8   OpenXmlReader re = OpenXmlReader.Create(sw.BaseStream);
   9 
  10   re.Read();
  11   OpenXmlElement oxe = re.LoadCurrentElement();
  12   re.Close();
  13 }

Hope, this helps.

openxml/Convert-an-XElement-to-an-OpenXmlElement (last edited 2021-06-02 06:08:34 by zbjxb)