Deep inside Java Web development-The core basics (see Zhang Xiaoxiang: 's book note one) __java

Source: Internet
Author: User
Tags xml parser java web

First, the XML foundation

1. As a general Data Interchange Format, XML is used more and more widely. Many of the current system's configuration files are in XML format. A configuration file is a file that records configuration information for an application. For example, when a program connects to a database system on a network, you need to specify the IP address of the database server, the network listener port number of the server, the name of the database, the user name, and password, which can be treated as configuration information for the application, i.e. do not write this information to death in the source program. Instead, it is written in a text file. When the application wants to connect to the database system, read the required information from the text file, and if the information of the connected database system changes, you only need to modify the text file without modifying the source program, which is the application's configuration file. Traditional configuration files typically take the following format:

#DB. Properties

dbserver=192.168.0.100

port=1443

Database=emp

Username=abc

Password=123

Configuration files in this format can only express some simple information, and it is difficult to express the information that has hierarchies and data items to dynamically increase. XML-formatted configuration files can easily express this hierarchy. Therefore, to learn and Master Java Web Development technology, there must be some basic knowledge of XML language.

2. You must include an XML document declaration in a complete XML document that must be in the first line of the document. This declaration indicates that the document is an XML document and the specification of which XML version is followed. The simplest XML document declaration syntax is as follows:

<?xml version= "1.0"?>

In the "<" and "?" Between, "?" and ">" and the First "?" There can be no spaces between XML and this is a manifestation of the strict nature of XML syntax. The version attribute in a declaration statement represents the versions of XML, because the parser for different versions is bound to differ, although there are currently only 1.0 versions, the version attribute must be specified in the declaration. Because a different set of character encodings can be used to write an XML document with exactly the same character content, the XML software tool (including the parser) needs to know the character encoding used by the XML document. This can be indicated by specifying the encoding attribute in the XML document declaration, for example, by using the following statement to indicate that the character encoding in the document is GB2312 encoded

<?xml version= "1.0" encoding= "gb2312"?>

The XML1.0 specification of the Consortium stipulates that all XML parsers must accept UTF-8 and UTF-16 encoded Unicode characters, so the software tools that conform to XML specifications must support both Unicode encodings. If the encoding property is not set in the XML declaration to explicitly specify the character encoding used for the document, it is treated in Unicode encoding. The XML parser can automatically detect whether the Unicode encoding in the document is UFT-8 or UTF-16 by looking for the byte order mark at the beginning of the XML document. XML Document declaration statement, you can also specify another optional attribute: Standalone, for example:

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"?>

The standalone property is used to indicate whether the document is independent, and if it is set to Yes, it means that the document does not depend on any outside file and can exist independently, that is, no DTD file is needed to verify that the identity is valid, and that the XSL, CSS file is not required to control its appearance The default value for the standalone property is yes. Note: If you set both the encoding and standalone properties, the standalone property is located after the encoding property, and for XML that has a Chinese character, The characters can be encoded by Unicode or GB2312 (Simplified Chinese character encoding) encoding.

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.