Python class library 31 [Dom + sax parsing XML and HTML]

Source: Internet
Author: User

 

Standard Generalized Markup Language (SGML) is the standard universal Markup Language Hypertext Markup Language (HTML) hypertext markup language.

Extensible Markup Language (XML) Extensible Markup Language

 

SGML, HTML, and XML can all be parsed using the following Sax and Dom methods:

SGML is currently the highest level standard for commonly used hypertext formats. It is a metalanguage that can define Markup languages, or even a conventional method that does not require <>. Both HTML and XML are derived from SGML. html is an application of SGML and cannot be used to define other Markup languages.

XML can be considered as a subset of SGML. XML is generated to simplify SGML for more general purposes, such as semantic web. It has been applied to a large number of occasions, more famous XHTML, RSS, XML-RPC and soap.

 

 

A. Sax and Dom

SAX (Simple API for XML) and Dom (Document Object Model) are two ways to process XML files.
Sax is an event-driven API. Parsing XML documents using sax involves two parts: the parser and the event processor. The parser is responsible for reading XML documents and sending events to the event processor. For example, the element starts with the element end event, and the event processor is responsible for responding to the event and processing the transmitted XML data. Dom allows you to use hierarchical object models to access information stored in XML documents. Dom generates a node tree (based on the structure and information of XML documents). You can use this tree to access your information. The text information in the XML document is transformed into a node of a group of trees. Dom is essentially a collection of nodes.

 

Through the analysis of Sax and Dom, they have their own different application fields. Sax is suitable for processing the following problems: 1. Processing large files; 2. Only part of the file content is required, or you only need to get specific information from the file. 3. When you want to create your own object model. Dom is suitable for handling the following problems: 1. files need to be modified; 2. files need to be accessed randomly.

 

2. Read and Write xmlpython31 advanced [Use minidom to read and write XML] python31 advanced [use XML. etree. elementtree to read and write XML] python31 advanced [use SAX to parse XML]

 

3. parse HTML libs:

The syntax requirements of HTML are not so strict and the labels are relatively fixed. Therefore, compared with XML, the parser requires more intelligence and easier processing of HTML tags.

Http://lxml.de/http://www.crummy.com/software/BeautifulSoup/http://code.google.com/p/html5lib/

 

Complete!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.