Use AspxParser
:
var parser = new AspxParser(rootDirectory);
var source = new AspxSource(fileName, fileCode);
AspxParseResult aspxTree = parser.Parse(source);
Result AspxParseResult
contains a reference to a parse tree RootNode
and to a list with parse errors ParserErrors
.
Use DepthFirstAspxVisitor
or DepthFirstAspxWithoutCloseTagVisitor
visitors:
public AspxToCsConverter : DepthFirstAspxWithoutCloseTagVisitor<string>
{
public override string Visit(AspxNode.Root node)
{
...
}
public override string Visit(AspxNode.HtmlTag node)
{
...
}
}
var converter = new AspxToCsConverter();
var result = aspxTree.Root.Accept(converter);
AspxParser is licensed under the MIT License.