• Stars
    star
    327
  • Rank 128,686 (Top 3 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created about 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service

XmlParser

logo image

Build status NuGet package NuGet package for VS Editor

A Roslyn-inspired full-fidelity XML parser with no dependencies and a simple Visual Studio XML language service.

  • The parser produces a full-fidelity syntax tree, meaning every character of the source text is represented in the tree. The tree covers the entire source text.
  • The parser has no dependencies and can easily be made portable. I would appreciate a high quality pull request making the parser portable.
  • The parser is based on the section of the Roslyn VB parser that parses XML literals. The Roslyn code is ported to C# and is made standalone.
  • The parser is error-tolerant. It will still produce a full tree even from invalid XML with missing tags, extra invalid text, etc. Missing and skipped tokens are still represented in the tree.
  • The resulting tree is immutable and follows Roslyn's green/red separation for maximum reusability of nodes.
  • The parser has basic support for incrementality. Given a previous constructed tree and a list of changes it will try to reuse existing nodes and only re-create what is necessary.
  • This library is more low-level than XLinq (for instance XLinq doesn't seem to represent whitespace around attributes). Also it has no idea about XML namespaces and just tells you what's in the source text (whereas in XLinq there's too much ceremony around XML namespaces).

This is work in progress and by no means complete. Specifically:

  • XML DTD is not supported (Roslyn didn't support it either)
  • Code wasn't tuned for performance and allocations, I'm sure a lot can be done to reduce memory consumption by the resulting tree. It should be pretty efficient though.
  • We reserve the right to accept only very high quality pull requests. We have very limited time to work on this so I ask everybody to please respect that.

Download from NuGet:

Try it!

https://xmlsyntaxvisualizer.azurewebsites.net/index.html

The above app leverages the parser and can help you visualize the resulting syntax tree generated from an XML document.

Code is available at https://github.com/garuma/XmlSyntaxVisualizer C# UWP example at https://github.com/michael-hawker/XmlSyntaxVisualizerUWP

Also see the blog post: https://blog.neteril.org/blog/2018/03/21/xml-parsing-roslyn/

Resources about Immutable Syntax Trees: https://github.com/KirillOsenkov/Bliki/wiki/Roslyn-Immutable-Trees

FAQ:

How to find a node in the tree given a position in the source text?

https://github.com/KirillOsenkov/XmlParser/blob/master/src/Microsoft.Language.Xml/Utilities/SyntaxLocator.cs#L24

SyntaxLocator.FindNode(SyntaxNode node, int position);

More Repositories

1

MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
C#
1,449
star
2

SourceBrowser

Source browser website generator that powers http://referencesource.microsoft.com and http://sourceroslyn.io
C#
1,063
star
3

RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
C#
822
star
4

MetadataTools

Various tools and helpers to read assembly metadata.
C#
178
star
5

QuickInfo

http://quickinfo.io - a search textbox with extensible "answers" (calculator, unit-converter, colors, ascii/unicode, etc). See demo at http://quickinfo.io/?demo
C#
172
star
6

CodeCleanupTools

A set of command-line tools to cleanup C# and VB source code.
C#
122
star
7

Undo

Simple .NET Undo/Redo framework with merging and transactions
C#
102
star
8

ContentSync

Directory copy/sync/mirror tool that uses file contents (not timestamps) to avoid touching identical files
C#
64
star
9

LargeAddressAware

A build tools package that adds support for making 32-bit exes LARGEADDRESSAWARE
C#
52
star
10

StructuredEditor

An experimental structured code editor prototype for a subset of C#
C#
50
star
11

LayoutDesigner

A prototype Silverlight UI layout designer. Works with basic panels (StackPanel and Grid). Built entirely using drag-n-drop. XAML can be copied to clipboard. Built with Silverlight 4 and runs in the browser.
C#
48
star
12

LiveGeometry

Interactive geometry CAD-like educational software
Visual Basic 6.0
30
star
13

Bliki

Blog/Wiki/Notes
30
star
14

MathParser

Parser for arithmetic expressions
C#
21
star
15

MEFMetadata

Metadata-based part discovery for MEF, uses the Roslyn metadata reader and is faster than reflection.
C#
18
star
16

MSBuildLog

Source code for http://msbuildlog.com
HTML
16
star
17

NuGetTools

C#
16
star
18

Misc

Various small and one-off projects just barely too big to throw away
C#
14
star
19

dotfiles

My dotfiles and Mac config
Shell
13
star
20

Benchmarks

My collection of benchmarks for random pieces of code
C#
13
star
21

WpfSendKeys

SendKeys for WPF
C#
12
star
22

DumpTools

Tools to analyze managed .dmp files using ClrMd
C#
8
star
23

MEFTools

Tools to help working with MEF
C#
7
star
24

Dia2Dump

Taken from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\DIA SDK\Samples\DIA2Dump
C++
6
star
25

MyOwnSearchEngine

This repo has moved to https://github.com/KirillOsenkov/QuickInfo
JavaScript
3
star
26

DiagnosticMargin

C#
3
star
27

VSInstanceFinder

Finds the locations of all installed VS 2017 instances
C#
2
star
28

ColorTools

JavaScript
2
star
29

MagicSquare

Simple addition/multiplication table for kids
C#
2
star
30

ApplyPatch

Simple utility to apply a patch to a set of files
C#
1
star
31

MefHost

Test MEF host to repro a bug
C#
1
star
32

guilabs

Source code for http://guilabs.net
HTML
1
star
33

BeachballPoker

C#
1
star