推出您自己的XML解析器/XML解析算法? [英] Roll your own XML parser / XML parsing algorithm?

查看:75
本文介绍了推出您自己的XML解析器/XML解析算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,作为一个有趣的项目,我决定编写自己的XML解析器.不,不分析特定文档,不,不使用XML解析器库.我的意思是编写代码以将任何XML文档解析为可用的数据结构.只是因为我喜欢挑战. :-)

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 parse out any XML document into a usable data structure. Just because I like the challenge. :-)

话虽如此,到目前为止,事实证明……很有趣.解析起来并不像它最初看起来那样容易(尤其是当您开始考虑特殊字符,CDATA,空标签,注释等)时.

With that said, so far it's proved to be... interesting. It's not as easy to parse (especially when you start taking into account special characters, CDATA, empty tags, comments, etc.) as it initially looked.

在任何人都知道的地方,是否存在任何有据可查的XML解析算法或解释?似乎到处都有记录良好的Queue和Stack以及BTree等等.等等.但是我不确定我是否见过简单的,记录良好的XML解析器算法...

Are there any well documented XML parsing algorithms or explanations anywhere that anyone knows of? It seems like there are well-documented Queue and Stack and BTree and etc. etc. etc. implementations everywhere, but I'm not sure I've ever seen a simple, well-documented XML parser algorithm...

我要重复:我不是正在寻找预构建的解析器库!我正在寻找有关如何创建自己的预构建解析器库的信息!不要告诉我使用外国人"或使用SAX"或其他任何东西.那不是我要的.

I repeat: I am not looking for a pre-built parser library! I am looking for information on how to create my own pre-built parser library! Do not tell me "use expat" or "use SAX" or whatever. That's not what I'm asking for.

推荐答案

Antlr 提供了教程.它将过程分为几个阶段:词法分析,解析,树解析等.看起来很有趣.

Antlr offers a tutorial on parsing XML. It breaks the process down into phases: lexing, parsing, tree parsing, etc. Looks pretty interesting.

这篇关于推出您自己的XML解析器/XML解析算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆