如何从头开始创建/编写一个简单的XML解析器? [英] How to create/write a simple XML parser from scratch?

查看:89
本文介绍了如何从头开始创建/编写一个简单的XML解析器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从头开始创建/编写一个简单的XML解析器?



我想知道英文的简化基本步骤是什么,而不是代码示例。 / p>

一个好的解析器如何设计?我知道不应该在解析器中使用正则表达式,但是正则表达式在解析XML中的作用是多少?



推荐使用什么数据结构?我应该使用链接列表来存储和检索节点,属性和值吗?



我想学习如何创建XML解析器,以便可以在D编程中编写一个语言。

解决方案

如果您不知道如何编写解析器,则需要阅读一些内容。掌握有关编译器编写的任何书籍(许多最好的书籍都是30或40年前写的,例如Aho和Ullmann),并学习有关词法分析和语法分析的章节。 XML本质上没有什么不同,除了词法和语法阶段没有像某些语言那样清楚地彼此隔离。



一个警告,如果您想编写一个完全符合标准的XML解析器,那么您将花费90%的精力在规范的晦涩难懂的角落中获得边缘案例。处理大多数XML用户甚至不知道的参数实体之类的东西。


How to create/write a simple XML parser from scratch?

Rather than code samples, I want to know what are the simplified, basic steps in English.

How is a good parser designed? I understand that regex should not be used in a parser, but how much is regex's role in parsing XML?

What is the recommended data structure to use? Should I use linked lists to store and retrieve nodes, attributes, and values?

I want to learn how to create an XML parser so that I can write one in D programming language.

解决方案

If you don't know how to write a parser, then you need to do some reading. Get hold of any book on compiler-writing (many of the best ones were written 30 or 40 years ago, e.g. Aho and Ullmann) and study the chapters on lexical analysis and syntax analysis. XML is essentially no different, except that the lexical and grammar phases are not as clearly isolated from each other as in some languages.

One word of warning, if you want to write a fully-conformant XML parser then 90% of your effort will be spent getting edge cases right in obscure corners of the spec dealing with things such as parameter entities that most XML users aren't even aware of.

这篇关于如何从头开始创建/编写一个简单的XML解析器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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