Hi @Gael , Welcome to Microsoft Q&A,
Use the WordprocessingDocument.FromFlatOpcString method provided by the Open XML SDK to parse Flat OPC XML. If you simply want to get <w:t>, there is an example for reference:
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using System;
using Paragraph = DocumentFormat.OpenXml.Wordprocessing.Paragraph;
namespace _2_18_1
{
class Program
{
static void ParseFlatOpcXml(string flatOpcXml)
{
// Create a WordprocessingDocument directly using the FromFlatOpcString method
using (var wordDoc = WordprocessingDocument.FromFlatOpcString(flatOpcXml))
{
var body = wordDoc.MainDocumentPart.Document.Body;
Paragraph previousParagraph = null;
foreach (var para in body.Elements<Paragraph>())
{
// Try to get paragraph properties
var pPr = para.ParagraphProperties;
NumberingProperties numPr = null;
if (pPr != null)
{
numPr = pPr.NumberingProperties;
}
bool isListItem = false;
if (numPr != null)
{
// There is an explicit list numbering property
isListItem = true;
}
else
{
// If the current paragraph has no paragraph properties, determine whether the previous paragraph is a list item
if (previousParagraph != null)
{
var prevPPr = previousParagraph.ParagraphProperties;
if (prevPPr != null && prevPPr.NumberingProperties != null)
{
// Assuming that the previous paragraph is a list item, the current paragraph may also be a list item
isListItem = true;
}
}
}
// Perform different processing depending on whether it is a list item
if (isListItem)
{
Console.WriteLine("List item: " + para.InnerText);
}
else
{
Console.WriteLine("Normal paragraph: " + para.InnerText);
}
previousParagraph = para;
}
}
}
static void Main(string[] args)
{
string flatOpcXml = @"<?xml version=""1.0"" standalone=""yes""?>
<?mso-application progid=""Word.Document""?>
<pkg:package xmlns:pkg=""http://schemas.microsoft.com/office/2006/xmlPackage"">
<pkg:part pkg:name=""/_rels/.rels"" pkg:contentType=""application/vnd.openxmlformats-package.relationships+xml"" pkg:padding=""512"">
<pkg:xmlData>
<Relationships xmlns=""http://schemas.openxmlformats.org/package/2006/relationships"">
<Relationship Id=""rId1"" Type=""http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"" Target=""word/document.xml""/>
</Relationships>
</pkg:xmlData>
</pkg:part>
<pkg:part pkg:name=""/word/document.xml"" pkg:contentType=""application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"">
<pkg:xmlData>
<w:document xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"">
<w:body>
<w:p w:rsidR=""00F80704"" w:rsidRPr=""00AF0002"" w:rsidRDefault=""00F80704"" w:rsidP=""00F80704"">
<w:pPr>
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
</w:pPr>
<w:bookmarkStart w:id=""0"" w:name=""REQ_WORL3_0003""/>
<w:r w:rsidRPr=""00AF0002"">
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
<w:t>Key points:</w:t>
</w:r>
</w:p>
<w:p w:rsidR=""00F80704"" w:rsidRPr=""00AF0002"" w:rsidRDefault=""00F80704"" w:rsidP=""00F80704"">
<w:pPr>
<w:pStyle w:val=""Paragraphedeliste""/>
<w:numPr>
<w:ilvl w:val=""0""/>
<w:numId w:val=""1""/>
</w:numPr>
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
</w:pPr>
<w:r w:rsidRPr=""00AF0002"">
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
<w:t>point 1</w:t>
</w:r>
</w:p>
<w:p w:rsidR=""00F80704"" w:rsidRPr=""00AF0002"" w:rsidRDefault=""00F80704"" w:rsidP=""00F80704"">
<w:pPr>
<w:pStyle w:val=""Paragraphedeliste""/>
<w:numPr>
<w:ilvl w:val=""0""/>
<w:numId w:val=""1""/>
</w:numPr>
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
</w:pPr>
<w:r w:rsidRPr=""00AF0002"">
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
<w:t>point 2</w:t>
</w:r>
</w:p>
<w:p w:rsidR=""00F80704"" w:rsidRDefault=""00F80704"" w:rsidP=""00F80704"">
<w:r w:rsidRPr=""00AF0002"">
<w:rPr>
<w:highlight w:val=""cyan""/>
<w:lang w:val=""en-US""/>
</w:rPr>
<w:t>point 3</w:t>
</w:r>
<w:bookmarkEnd w:id=""0""/>
</w:p>
<w:sectPr w:rsidR=""00000000"">
<w:pgSz w:w=""12240"" w:h=""15840""/>
<w:pgMar w:top=""1417"" w:right=""1417"" w:bottom=""1417"" w:left=""1417"" w:header=""720"" w:footer=""720"" w:gutter=""0""/>
<w:cols w:space=""720""/>
</w:sectPr>
</w:body>
</w:document>
</pkg:xmlData>
</pkg:part>
</pkg:package>";
ParseFlatOpcXml(flatOpcXml);
Console.ReadLine();
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.