1. The difference between XML and HTML
XML is not an alternative to HTML, and XML is a complement to HTML.
It is important to understand that XML does not replace HTML. In most Web applications, XML is used to transfer data, and HTML is used to format and display data.
The best description of XML is that XML is an information transfer tool that is independent of software and hardware.
Compare content |
Html |
XML |
Scalability |
does not have extensibility |
is a meta-markup language that allows you to customize new tags |
Role |
Focus is the appearance of the data, designed to display information |
Designed to transmit and store data, focusing on the content of the data |
Syntax requirements |
Does not require nesting, pairing, etc. of tags, and does not require a certain order between tags |
Strict requirements for nesting, pairing, and conforming to a unified sequential structure |
Readability maintainability |
Difficult to read and maintain |
Clear structure, easy to read and maintain |
Data and formats |
Data and formatting together |
Data and format separation |
2. XML parsing
There are two ways to parse XML: DOM mode and sax mode
Dom:document object model. This approach is a way of dealing with XML as recommended by the consortium.
Sax:simple API for XML. This is not an official standard, it belongs to the open source community Xml-dev, and almost all XML parsers support it.
XML Parsing Development Package
JAXP: It is the analytic standard implementation that sun company launches. Jdk
DOM4J: is the open source organization launched the Analytic Development package. (Some of Sun's technology implementations are in use)
JDom: is the open source organization launched the Analytic Development package.
3, JAXP
JAXP: (Java API for XML Processing) The development package is part of the javase, which consists of the following packages and their sub-packages: (Javase API)
Org.w3c.dom: Provides a standard interface for parsing XML in DOM mode
Org.xml.sax: Provides a standard interface for parsing XML in sax mode
Javax.xml: provides classes to parse XML documents
In the Javax.xml.parsers package, several factory classes are defined. We can get the DOM and Sax parser objects that parse the XML document by invoking these factory classes.
Documentbuilderfactory
SAXParserFactory
Parsing the XML first to get to the parser
The documentbuilderfactory used in the Javax.xml.parsers package to create the parser object for the DOM pattern, Documentbuilderfactory is an abstract factory class,
It cannot be instantiated directly, but the class provides a Newinstance method that automatically creates a factory object and returns based on the parser installed by default on the local platform.
Call the Documentbuilderfactory.newinstance () method to get the factory that created the DOM parser.
Invokes the Newdocumentbuilder method of the factory object to get the DOM parser object.
Invoking the Parse () method of the DOM parser object parses the XML document and obtains the Document object representing the entire file, which can be manipulated using the DOM attribute for the entire XML document.
DOM Models (Document Object model)
When parsing an XML document, the DOM parser parses all the elements in the document into a Node object (nodes) according to the hierarchical relationships that appear.