Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2021-06-02 06:07:39
Size: 692
Editor: zbjxb
Comment:
Revision 3 as of 2021-06-02 06:08:21
Size: 718
Editor: zbjxb
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
You can convert a given OpenXmlElement to a XElement using the following code: You can convert a given !OpenXmlElement to a XElement using the following code:
Line 7: Line 7:
To convert an XElement to an OpenXmlElement try the following code: }}}
Line 9: Line 9:
To convert an XElement to an !OpenXmlElement try the following code:
{{{#!highlight c#

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 }
  14 Hope, this helps.

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