私はすでにこの問題の理由を見つけているので、これは実際には問題ではありません
子孫は、このコードを使用して取得されます。
using System.IO;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace Testolini
{
class Program
{
static void Main(string[] args)
{
var filename = Path.GetTempFileName();
var word = WordprocessingDocument.Create(filename, DocumentFormat.OpenXml.WordprocessingDocumentType.Document);
word.AddMainDocumentPart();
word.MainDocumentPart.Document = new Document(
new Body(
new Paragraph(
new Run(
new Paragraph(
new Run(
new Text("test1"))),
new Paragraph(
new Run(
new Text("test2"))),
new Paragraph(
new Run(
new Text("test3")))))));
word.Close();
using (var memorystream = new MemoryStream(File.ReadAllBytes(filename)))
{
var word2 = WordprocessingDocument.Open(memorystream, true);
var descendants = word2.MainDocumentPart.Document.Body.Descendants();
word.Close();
}
}
}
}
同じ問題が発生した場合。XMLファイルがECMA標準で検証されていないことが原因である可能性があります。私の場合、問題は段落がネストされていることでした。
bytearrayとmemorystreamを使用してドキュメントを開くと、問題が発生します。要素が検証されているようで、検証が失敗した場合はOpenXmlUnknownElementになります。
誰かがより良い説明とおそらくこの問題のより正確な理由を持っているなら、私はそれについてもっと学びたいです。