Transfer from Zhang Xiaoxiang: XML foundation

xiaoxiao2021-04-05  243

XML is used as a common data exchange format, which is more and more wide. At present, many system configuration files use XML format. The many profiles involved in this book are XML format, and the new JSP specification has also launched a JSP document with XML syntax, so we must learn and master Java Web. Development technology must have some basic XML language knowledge. Due to the versatility and wide application of XML, many places have to use XML knowledge in many places after readers, so the understanding and mastery of XML knowledge is already engaged in e-commerce websites and related systems. The basic knowledge must be mastered by the programmer.

F pointing to the prostitute: What is a configuration file?

The profile is a file that records the configuration information of the application. For example, when a program is to connect to a database system on the network, you need to specify the IP address of the database server, the server's network listening port number, the name, username, and password of the database, which can be treated as the configuration information of the application. Do not write this information in the source program, but written in a text file. When the application is to connect to the database system, read the required information from the text file. If the information of the connected database system has changed, you only need to modify the text file without modifying the source program, this text file is application Profile of the program. Traditional profiles are usually used in the following format:

# Db.properties

DBServer = 192.168.0.100

Port = 1443

Database = EMP

Username = zxx

PASSWORD = 123

The configuration file above this format can only represent some simple information, and it is difficult to express information with hierarchical and data items to be dynamically increased. For example, if you want to express "every province and governor in a country, each city and mayor of each city, each town of each city and the descendant name ", It is difficult to express using the above format. Profiles in XML format are easy to express this hierarchy, please refer to the explanation of the following sections of this chapter.

Document statement

In a complete XML document, you must include an XML document declaration that must be in the first line of the document. This statement indicates that the document is an XML document and which XML version is compiled. The simplest XML document declaration syntax is as follows:

Between "" and "?", "?" And ">" and the first "?" And XML can't have spaces, this is an embodiment of XML syntax strictness. In the second "?", There is no or one or more spaces. The version of the Version property in the statement represents the version of the XML, as the parser will definitely vary from the resolution of different versions, although only version 1.0 is currently, but must specify the Version property in the statement.

Since people can use different character coding sets to write a character content exactly the same XML document, the XML software tool (including the analyzer) needs to know the character encoding used by the XML document. This can be explained by specifying an encoding property in an XML document declaration, for example, using the following statement to indicate the character encoding mode in the document is GB2312 encoding.

In the XML1.0 specification of W3C, all XML parsers must accept UTF-8 and UTF-16 encoded Unicode characters, so the software tools that meet the XML specification must support both Unicode encodes. If an encoding property is set in the XML declaration to explicitly specify the character encoding method used by the document, it will be treated in Unicode. The XML parser can automatically detect Unicode encoding in the document UTF8 by looking for byte sequential marks at the beginning of the XML document. That is, the default setting of the Encoding property is Unicode encoding. If the character in the document is used as UTF-8 or UTF-16 as encoding, this property may not be set. In the XML document declaration statement, you can also specify another optional attribute: Standalone, for example:

The Standalone property is used to explain whether the document is independent. If it is set to "Yes", it means that the document does not depend on any files that can be dependent on the outside, that is, it does not require the DTD file to verify whether the identity is effective, nor Unex, CSS files are required to control their display appearance; when the Standalone property is set to "NO", the document depends on a file outside, for example, depending on a DTD file or XSL, CSS file. The default value of the Standalone property is "YES".

Note: If the Encoding and Standalone properties are set, the Standalone property is located after the Encoding property.

: Hand experience: deepen understanding of Encoding properties

For XML containing Chinese characters, the characters may be encoded or GB2312 (Simplified Chinese character encoding) encoding, if the character in the document is encoded, the Encoding property is GB2312, by one Experiments to illustrate this problem.

(1) Create a file named book.xml with a notebook program with Windows, and the contents of the file are shown in routine 1-1. Routines 1-1 book.xml

Java Employment Training Tutorial </ Title></p> <p>张孝祥 </ author></p> <p><Price> 39.00 元 </ Price></p> <p></ Book></p> <p><Book></p> <p><Title> JavaScript webpage development </ book name></p> <p>张孝祥 </ author></p> <p><Price> 28.00 </ Price></p> <p></ Book></p> <p></ Bookshelf></p> <p>(2) Open the book.xml file with the browser above IE5.0, see the result is shown in Figure 1.2. The error prompt information is "Intaordable characters" in text content ", which is because the browser will use the default Unicode encoding to resolve the document with the default Unicode encoding in the Book.xml XML document declaration statement. And the characters in this document actually use GB2312 encoding, not Unicode encodes.</p> <p>(3) Click the "View" "View" menu of the browser, modify the first line of the open book.xml file content into the following form: <? XML Version = "1.0" encoding = "GB2312"? > After saving modifications, refresh the browser window to display the Book.xml file, see the result is shown in Figure 1.3. Click the minus sign (-) before a tag (-), and all the contents nested in the tag will be folded, the minus sign (-) in front of the tag will also become a plus sign ( ). Click the plus sign ( ) in front of a tag, nesting all the content in this tag will be expanded, the plus sign ( ) in front of the tag will also become minus (-). (4) In the Notepad of the book.xml file above, click the "File" à "Save As" menu, in the Open Save As dialog box, select "Save Type" as "All Files", Encoded as "UTF-8", as shown in Figure 1.4. After saving the book.xml file with UTF-8, although there is no change in the record in the Notepad program window, the data stored inside the book.xml file has changed, which is based on the file size before and after the comparison Book.xml saved. It can be seen. Refresh the browser window to display the Book.xml file, see the result is shown in Figure 1.5. Because the current book.xml file has been converted to UTF-8, the eNCoding property is specified in the initial declaration of the document to be GB2312, so the browser will errors when parsing the Book.xml file.</p> <p>(5) Modify the Encoding property of the Book.xml's document to UTF-8. After saving, refresh the browser window to display the book.xml file, you can see the normal display of Figure 1.3.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-132000.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="132000" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.031</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'n41L6Heg3U_2F5ixquYVtcHr8Rhvlex70My4BQdrgwNzIQtoUohTu7nG7GsczMaAkPxueJVAAJLVg2JEKtsp5b0g_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>