-
Notifications
You must be signed in to change notification settings - Fork 586
Expand file tree
/
Copy pathOpenXmlPartReaderAsync.cs
More file actions
110 lines (93 loc) · 3.17 KB
/
OpenXmlPartReaderAsync.cs
File metadata and controls
110 lines (93 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
#if TASKS_SUPPORTED
using System.Threading.Tasks;
#endif
using System.Xml;
namespace DocumentFormat.OpenXml;
/// <summary>
/// Represents the Open XML part reader class.
/// </summary>
public partial class OpenXmlPartReader : OpenXmlReader
{
/// <summary>
/// Gets the type of the current node in the XML document being read.
/// </summary>
/// <remarks>
/// The <see cref="XmlNodeType"/> indicates the type of the current node, such as
/// <c>Element</c>, <c>Attribute</c>, <c>Text</c>, <c>CDATA</c>, <c>Comment</c>, or others.
/// This property provides information about the structure of the XML document
/// and is useful for determining how to process the current node.
/// </remarks>
public override XmlNodeType NodeType
{
get
{
return _xmlReader.NodeType;
}
}
#if TASKS_SUPPORTED
/// <summary>
/// Asynchronously reads the next element in the Open XML document.
/// </summary>
/// <returns>
/// A task that represents the asynchronous read operation. The task result is <c>true</c> if the next element
/// was read successfully; <c>false</c> if there are no more elements to read.
/// </returns>
public async override Task<bool> ReadAsync()
{
ThrowIfObjectDisposed();
bool result = await MoveToNextElementAsync().ConfigureAwait(false);
if (result && !ReadMiscNodes)
{
// skip miscellaneous node
while (result && IsMiscNode)
{
result = await MoveToNextElementAsync().ConfigureAwait(false);
}
}
return result;
}
public async override Task<bool> ReadFirstChildAsync()
{
//ThrowIfObjectDisposed();
//bool result = await MoveToFirstChildAsync().ConfigureAwait(true);
//if (result && !ReadMiscNodes)
//{
// // skip miscellaneous node
// while (result && IsMiscNode)
// {
// result = MoveToNextSibling();
// }
//}
//return result;
return true;
}
private async Task<bool> MoveToNextElementAsync()
{
if (_elementState == ElementState.Null)
{
return await ReadRootAsync().ConfigureAwait(false);
}
return MoveToNextElementHelper();
}
private async Task<bool> ReadRootAsync()
{
Debug.Assert(_elementState == ElementState.Null);
Debug.Assert(_elementStack.Count == 0);
// TODO: should we take care of entity? <!DOCTYPE page [ <!ENTITY company "Microsoft"> ]>
// TODO: is it OK that we skip all prologue ( DOCTYPE, Comment, PT ) ?
await _xmlReader.MoveToContentAsync().ConfigureAwait(false);
while (!_xmlReader.EOF && _xmlReader.NodeType != XmlNodeType.Element)
{
await _xmlReader.SkipAsync().ConfigureAwait(false);
}
return ReadRootHelper();
}
#endif
}