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

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

问题描述

如何从头开始创建/编写一个简单的 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.

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

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?

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

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

推荐答案

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

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.

提醒一句,如果您想编写一个完全符合标准的 XML 解析器,那么您将花费 90% 的精力在规范的晦涩角落处理边缘情况,处理诸如大多数 XML 用户所使用的参数实体之类的事情甚至不知道.

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天全站免登陆