This document is for an old version of Python that is no longer supported. You should upgrade and read the Python 当前稳定版本的文档.

# 19. 结构化标记处理工具

Python 支持各种模块，以处理各种形式的结构化数据标记。 这包括使用标准通用标记语言（SGML）和超文本标记语言（HTML）的模块，以及使用可扩展标记语言（XML）的几个接口。

It is important to note that modules in the `xml` package require that there be at least one SAX-compliant XML parser available. Starting with Python 2.3, the Expat parser is included with Python, so the `xml.parsers.expat` module will always be available. You may still want to be aware of the PyXML add-on package; that package provides an extended set of XML libraries for Python.

The documentation for the `xml.dom` and `xml.sax` packages are the definition of the Python bindings for the DOM and SAX interfaces.

- 19.1. `HTMLParser` — Simple HTML and XHTML parser
  - 19.1.1. Example HTML Parser Application
  - 19.1.2. `HTMLParser` Methods
  - 19.1.3. Examples
- 19.2. `sgmllib` — Simple SGML parser
- 19.3. `htmllib` — A parser for HTML documents
  - 19.3.1. HTMLParser Objects
- 19.4. `htmlentitydefs` — Definitions of HTML general entities
- 19.5. XML处理模块
- 19.6. XML 漏洞
  - 19.6.1. defused packages
- 19.7. `xml.etree.ElementTree` — ElementTree XML API
  - 19.7.1. 教程
    - 19.7.1.1. XML树和元素
    - 19.7.1.2. 解析XML
    - 19.7.1.3. 寻找有趣的元素
    - 19.7.1.4. 修改XML文件
    - 19.7.1.5. 构建XML文档
    - 19.7.1.6. 使用命名空间解析XML
    - 19.7.1.7. 其他资源
  - 19.7.2. XPath支持
    - 19.7.2.1. 示例
    - 19.7.2.2. 支持的XPath语法
  - 19.7.3. 参考
    - 19.7.3.1. 函数
    - 19.7.3.2. 元素对象
    - 19.7.3.3. ElementTree 对象
    - 19.7.3.4. QName Objects
    - 19.7.3.5. TreeBuilder Objects
    - 19.7.3.6. XMLParser对象
- 19.8. `xml.dom` — The Document Object Model API
  - 19.8.1. 模块内容
  - 19.8.2. Objects in the DOM
    - 19.8.2.1. DOMImplementation Objects
    - 19.8.2.2. 节点对象
    - 19.8.2.3. 节点列表对象
    - 19.8.2.4. 文档类型对象
    - 19.8.2.5. 文档对象
    - 19.8.2.6. 元素对象
    - 19.8.2.7. Attr 对象
    - 19.8.2.8. NamedNodeMap 对象
    - 19.8.2.9. 注释对象
    - 19.8.2.10. Text 和 CDATASection 对象
    - 19.8.2.11. ProcessingInstruction 对象
    - 19.8.2.12. 异常
  - 19.8.3. 一致性
    - 19.8.3.1. 类型映射
    - 19.8.3.2. Accessor Methods
- 19.9. `xml.dom.minidom` — Minimal DOM implementation
  - 19.9.1. DOM Objects
  - 19.9.2. DOM Example
  - 19.9.3. minidom and the DOM standard
- 19.10. `xml.dom.pulldom` — Support for building partial DOM trees
  - 19.10.1. DOMEventStream Objects
- 19.11. `xml.sax` — Support for SAX2 parsers
  - 19.11.1. SAXException Objects
- 19.12. `xml.sax.handler` — Base classes for SAX handlers
  - 19.12.1. ContentHandler 对象
  - 19.12.2. DTDHandler 对象
  - 19.12.3. EntityResolver 对象
  - 19.12.4. ErrorHandler 对象
- 19.13. `xml.sax.saxutils` — SAX 工具集
- 19.14. `xml.sax.xmlreader` — Interface for XML parsers
  - 19.14.1. XMLReader 对象
  - 19.14.2. IncrementalParser 对象
  - 19.14.3. Locator 对象
  - 19.14.4. InputSource 对象
  - 19.14.5. The `Attributes` Interface
  - 19.14.6. The `AttributesNS` Interface
- 19.15. `xml.parsers.expat` — Fast XML parsing using Expat
  - 19.15.1. XMLParser对象
  - 19.15.2. ExpatError Exceptions
  - 19.15.3. 示例
  - 19.15.4. Content Model Descriptions
  - 19.15.5. Expat error constants