XML Easy Learning Manual (4) XML Syntax

xiaoxiao2021-03-06  102

Chapter 4 XML Syntax Outline: One. Xml Syntax Rules II. The grammatical three of the elements. The syntax of the symbol. The syntax of the syntax. What is already XML, its implementation principle, and related terms. Next, we start learning XML's grammatical specification and write your own XML document. I. xml syntax rule XML document and HTML's original code is similar, and it is also identified by identity. Creating an XML document must follow the following important rules: Rules 1: There must be an XML declaration statement that we have already mentioned when he learned in the next chapter. The statement is the first sentence of the XML document, its format is as follows: The role is to tell your browser or other handler: this The document is an XML document. The Version in the statement represents the version of the XML specification of the document. Standalone indicates whether the document comes with a DTD file. If there is, the parameter is NO; Encoding indicates the language encoding used by the document. The default is UTF-8. Rule 2: Is there a DTD file If the document is a "valid XML document" (see the last chapter), the document must have the corresponding DTD file and strictly abide by the DTD file formulation. The DTD file declaration statement is followed behind the XML declaration statement, the format is as follows: where: "! Doctype" means you want to define a doctype; "Type- Of-doc "is the name of the document type, which is defined by yourself, usually the same DTD file name;" System / public "These two parameters use only one. System is the URL of the private DTD file used by the document, and the public refers to the URL of a public DTD file. "DTD-Name" is the URL and name of the DTD file. All DTD files are named ".dtd". We still use the above examples, should be written as this: rule 3: Note your Size in XML documentation, case is different.

and

are different logos. Note that when you write an element, you should keep the size before and after. For example: ajie , writing ajie is wrong. You'd better develop a habit, or all uppercase, or all lowercase, or uppercase the first letter. This reduces a document error due to case in casement. Rules 4: The attribute value is quoted in the HTML code, and the attribute value can be quoted, or may not be added. For example: Word and Word can be explained correctly by the browser. However, in XML, it is specified that all attribute values ​​must be quoted (can be single quotes, or two quotes), otherwise it will be considered an error.

Rule 5: All identities must have the corresponding end identity in HTML, the identifier may not be pair, ratio, lt; br>. In XML, all identities must be paired, there is a starting identifier, and must have an end identity. Otherwise it will be considered an error. Rules 6: All empty probes must also be closed to the identification of the identity between the identification pair. For example,
, , etc. In XML, it is specified that all identities must have an end identity. For such empty probability, the method processed in XML is that the original identity is finally added /, it is OK. For example:
should be written as
; should be written as ; should be written as

Chapter 4 XML Syntax II. The syntax elements of the element are composed of a pair of identifications and the content therein. Just like this: Ajie. The name of the element and the name of the identity are the same. Identification can be further described with attributes. In XML, there is no reserved word, so you can use any words as the element name as you want. However, you must also comply with the following specification: 1. You can include letters, numbers, and other letters in the name; 2. Name cannot start with a number or "_" (underscore); 3. Name cannot be in letter XML (or XML or XML ..) At the beginning 4. The name cannot contain spaces 5. The middle cannot contain ":": (colon) in the middle of the ":" (colon) to make the element easier to read understanding and operation, we have some suggestions: 1. Do not use "." Because in many program languages, "." Is an object of the object, for example: font.color. The same reason "-" is also best not to use, must be used, instead of "_"; 2. The name is as short as possible. 3. The case is used to use the same standard. 4. Names can use non-English characters, such as Chinese. But some software may not be supported. (IE5 is currently supporting Chinese elements.) In addition, add a description of the property. In HTML, the property can be used to define the display format of the element, such as Word will display Word as red. In XML, the attribute is only a description of the identity, and is independent of the display of the element content. For example, the same sentence: Word does not display Word as red. (So, some netizen will ask: How to display the text as red in XML? This requires CSS or XSL, we will tell it in detail below.) Third. The syntax of the comment is to facilitate reading and understanding, in XML documentation Added additional information will not be interpreted by the program or the browser is displayed. The syntax of the comment is as follows: It can be seen that it is the same as the comment syntax in HTML, it is very easy. Develop good annotations habits will make your document more convenient for maintenance, sharing, and look more professional. Four. CDATA's grammatical CDATA full name Character Data, translated as character data. When we write an XML document, sometimes you need to display letters, numbers, and other symbols itself, such as "<", and in XML, these characters already have special meanings, what should we do? This requires the CDATA syntax. The syntax format is as follows: For example: ajie ]]> The content displayed on the page will be " ajie "

Chapter 4 XML Grammar 5. The syntax of namespaces namespaces translated into a name space. What is the role of name space? This contradiction occurs when we use others or multiple DTD files in an XML document: This may cause data confusion. For example, in a document

Wood Table
represents the table, and in another document
Namelist represents the table. If I need to handle these two documents at the same time, the name conflict will occur. We solve this problem, we introduced this concept of Namespaces. NameSpaces distinguishes the same identity as the same name is added to the identified name of an URL (URL). Namespaces also requires the beginning of the XML document, the statement of the statement is as follows: where youRName is the name of the namespaces, the URL is the URL of the name. Suppose the above "Table
" document comes from http://www.zhuozi.com, we can declare "Document XMLns: zhuozi = 'http://www.zhuozi.com'> and then in the latter identity Use the defined namespace: Wood Table This two
distinguish. Note: Setting URL is not said that this logo really wants to read it, just as a distinguished mark. Six.ntity's grammatical Entity translated into "entity". It effects similar to "macro" in Word, you can also understand the touchpad in DW, you can predefine an Entity, then call multiple times in one document, or call the same entity in multiple documents. Entity can include characters, text, and so on, using Entity is the benefits of: 1. It can reduce errors, multiple identical parts in the document only need to enter it over again. 2. It improves maintenance efficiency. For example, you have 40 documents that contain Copyright's Entity, if you need to modify this Copyright, you don't need all files to modify, just change the Entity statement initially defined. XML defines two types of Entity. One is the ordinary Entity we say here, is used in the XML document; the other is the parameter Entity, used in the DTD file.

Entity definition syntax is: For example, I want to define a copyright information: If my copyright information content and others share an XML file, I can also use external calls, syntax like this: ]> Define the reference syntax in the document is: & Entity-name; for example, copyright information defined above, writing when calling? Copyright; Complete example, you can copy Copyright.xml Watching example: ]> xml </ title > <author> ajie </ author> <email> ajie@aolhoo.com </ email> <date> 20010115 </ date> © right; </ myfile> Chapter 4 XML syntax seven.dtd syntax DTD is "effective XML documentation must file, we define the rules and interrelationships of elements and identities in the document through the DTD file. How to build a DTD file? Let's learn together: 1. Set the element element is the basic component of the XML document. You have to define an element in the DTD and then use it in the XML document. The element definition syntax is: <! Element Description (#pcdata, definition *> Description: "<! Element" is an element's statement, indicating that you want to define an element; declare "description", is the name of the element "(#Pcdata, definition) *>" is the use rule of this element. Rules define the contents and mutual relationships that the elements can be included. The following table summary lists the rules of the elements: 2. Elemental rules:</p> <p>Symbol Meaning Example #pcdata Contains Character or Text Data <MyFile (#pcdata)> Element MyFile Contains a text data #pcdata, element-name contains text and other child elements <myfile (# pcdtata, title)> MyFile element must contain text and Tosis child elements, use commas Separate <MyFile (Title, Author, Email)> MyFile Elements must be included in order | Use "|" or <myfile (title | Author | email)> MyFile Element Title or Author or Email child must be included. Name can only use the <myfile> MyFile element must contain the title child element, and can only be used once. Name? Use the <myfile (Title, Author, Email?)> MyFile element must contain the title child element, and can only be used once; can contain or do not include Author and Email child elements, but if used, only once. Name Use at least once or multiple <myfile (Title , Author?, email "must contain a title child element, and use at least once; next to follow the Author child element, or not to follow; finally must contain Email child elements And only once. Name * Using once, multiple, or at all, <myfile (title *)> MyFile elements can contain one, multiple or not containing the title child element () set group, can nescen <myfile (#pcdata | title) * > Element MyFile contains one or more text or title child elements. <Myfile ((title *, author ?, email) * | comment> MyFile element must contain some content, content or a comment; or multiple groups, groups contain: one, multiple or no title chub elements Then it is one or there is no Author child element, and then it is a necessary Email sub-element.</p> <p>In addition, we can also define attributes for the element, because we do not recommend the use of properties, which is not detailed here. Finally, let's summarize some of the previous four chapters, write a simple instance containing DTD, XML, and Script, which is easy to understand: 1. Put the following files as MyFile.dtd <! Element myfile (title, author)> <! Element Title (#pcdata)> <! Element Author (#pcdata)> 2. Then build XML document myfile.xml: <? Xml version = "1.0" encoding = "gb2312"> <! Doctype myfile system "Myfile .dtd "> <myfile> <title> XML Easy Learning Manual </ Title> <Author> Ajie </ Author> </ myfile> 3. Establishing HTML Document MyFile.html <HTML> <HEAD> <script language =" JavaScript "for =" window "Event =" online "> var xmldoc = new activ.xmldom"); xmldoc.async = "false"; xmldoc.load ("myfile.xml"); nodes = xmldoc.documentelement. ChildNodes; title.innerText = nodes.Item (0) .text; author.innertext = nodes.item (1) .text; </ script> <title> Tune XML data in HTML </ title> </ head> < body bgcolor = "# FFFFFF"> <b> title: </ b> <span id = "title"> </ span> <br> <b> author: </ b> <span id = "author"> < / span> <br> </ body> </ html> 4. Use IE5.0 or more browser</p> <p>Open myFile.html can see the effect. Ok, until today's fourth chapter, we have some basic understanding of XML. The fifth chapter I will explain the successful example of an XML practical application to show the power of XML. Let's take a look at the next chapter: XML instance analysis.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-95730.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="95730" 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.043</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 = 'KuP9yi5Z9vNbAYOrYoD0XgYe8lfkJdEIMzgKpzyXUz8iNTPYFb1dXbQjllTH0wSgNMoieH4uhAHdacgayX1nKA_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>