Roll your own XML parser / XML parsing algorithm?

前端 未结 4 696
无人及你
无人及你 2020-12-29 23:23

So, just as a fun project, I decided I\'d write my own XML parser. No, not to parse a specific document, and no, not using an XML parser library. I mean writing code to pars

4条回答
  •  感动是毒
    2020-12-30 00:00

    I don't know if it would be "cheating" in your book, but you could try parsing your XML with a ready-built all-purpose language parser like ANTLR. The result would be a list of tokens (if you just use the lexer) or a parse tree (if you include the parser) and you could then re-build the parse tree almost 1:1 into an XML structure.

    Maybe. I haven't thought about the ways in which XML might be different from "normal" ANTLR fodder like programming languages, and whether you would be able to define a suitable grammar.

提交回复
热议问题