Home > Java > javaTutorial > body text

Learning materials for xml parsing and generation

巴扎黑
Release: 2017-06-26 10:57:44
Original
1004 people have browsed it

Learning materials for xml parsing and generation:

-------------------------- ------------------------------------------------

Dom and SAX parsing methods are built-in in jdk, and there is no need to import third-party jar packages.

The SAX parsed characters(char[] ch, int start, int length) method will trigger this event as long as there is content between the label and the next label including line breaks\n or spaces. If If the two tags are right next to each other, they will not be triggered if there is no content.

Global variables need to be set to save the obtained values.

In the startElement(String uri, String localName, String qName,Attributes attributes) method, you can get the attribute value of the label that triggered the method

characters(char[] ch, int start, int length ) method to obtain the content of the tag body

endElement(String uri, String localName, String qName) method can encapsulate the content obtained from the previous two methods into an object

The core of DOM parsing only needs to obtain the Document object (dom object), and then perform various operations on the node. Note that the text content in the tag body is regarded as the child node of the tag.

---------------------

SAX generates XML files. This is different from the class used for SAX parsing. Same, the SAXTransformerFactory class is used.

DOM generates XML, and the DocumentBuilderFactory class used in DOM parsing is also used. It should be noted that the document object is used to generate a root node Element, and then the same Elements are connected behind the root node, and finally the root node Element is connected to the document object.

The above is the detailed content of Learning materials for xml parsing and generation. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!