Class DocumentSyntax
The span-preserving syntax tree of one markup text.
public sealed class DocumentSyntax
- Inheritance
-
DocumentSyntax
- Inherited Members
- Extension Methods
Remarks
Every character of Text belongs to exactly one node in Nodes or below, so the tree reproduces the text byte for byte, comments, formatting and entities included.
Parsing never throws. Malformed text produces Diagnostics, and the offending characters are kept as TextSyntax nodes.
Properties
Diagnostics
Gets the problems found while parsing; empty for well-formed markup.
public IReadOnlyList<Diagnostic> Diagnostics { get; }
Property Value
Elements
Gets every element under Root, the root first, in document order.
public IEnumerable<ElementSyntax> Elements { get; }
Property Value
HasErrors
Gets a value indicating whether Diagnostics is non-empty.
public bool HasErrors { get; }
Property Value
Nodes
Gets the top-level nodes: the root element and any whitespace, comments and processing instructions around it.
public IReadOnlyList<MarkupSyntaxNode> Nodes { get; }
Property Value
Root
Gets the root element, or null when the text has none.
public ElementSyntax? Root { get; }
Property Value
Text
Gets the text the tree was parsed from.
public string Text { get; }
Property Value
Methods
FindElementAt(int)
Finds the element whose start tag begins (its <) at start.
public ElementSyntax? FindElementAt(int start)
Parameters
startintThe offset of the element's
<.
Returns
- ElementSyntax
The element, or null when none starts there.
GetNamespacesInScope(ElementSyntax, bool)
Collects the namespace declarations in effect for element, keyed by prefix (the empty
string for the default namespace).
public IReadOnlyDictionary<string, string> GetNamespacesInScope(ElementSyntax element, bool includeSelf = false)
Parameters
elementElementSyntaxThe element to collect for.
includeSelfbooltrue to include
element's own declarations; false to collect only what it inherits from its ancestors.
Returns
- IReadOnlyDictionary<string, string>
The declarations, an inner declaration hiding an outer one with the same prefix.
Parse(string)
Parses text.
public static DocumentSyntax Parse(string text)
Parameters
textstringThe markup text.
Returns
- DocumentSyntax
The syntax tree.
Exceptions
- ArgumentNullException
textis null.
ResolvePrefix(ElementSyntax, string)
Resolves a namespace prefix the way the markup loader does, including its predeclared x prefix.
public string? ResolvePrefix(ElementSyntax element, string prefix)
Parameters
elementElementSyntaxThe element the prefix is used on.
prefixstringThe prefix, or an empty string for the default namespace.