XML Schema Usage

zhaozj2021-02-16  45

Author: Tuesday, April

You should now know how XML only shows the structure of the data and does not care about how the data is specifically described, whether the data is correct. The mandatory structured demand for the XML document is implemented by DTD (document type description). That is the topic previously described in this series of articles. In this article, we summarize the shortcomings of DTD, which is a more powerful standard XML Schema.

DTD's trouble

Using DTD Although the element, the desired element and how to organize the elements in a given XML document, it will be troublesome when you want to apply a data type for a particular element. The DTD specification strictly defines the structure, but only the content type specification of the relative function is supported, but the mandatory structured is not aware, such as how Date is specified, it must contain effective values?

This is to count XML Schema, XML Schema is currently submitted to W3C in 2001, which means that it will eventually become general purpose recommendations. If you are interested in this, you may wish to see the materials such as the W3C website to find some official documents and content. Note that other Schema definitions are also available, including Japanese standard Relax and Microsoft's XDR. However, XML Schema is the only recommended standard for W3C, so I only explain it in this article.

XML Schema not only allows you to define the structure of the XML document and allow you to constrain the contents of the document, which is different from DTD. In addition, an XML Schema itself is an XML document, and its label-based syntax is more clear than the special characters in the DTD.

SCHEMA Overview

XML Schema is created with a predetermined XML element and attribute, which define the structure and content mode of the document. The corresponding set of delicate rules (these rules are very interesting to represent DTDs) specify the legal use of each Schema element or attribute. If these rule parsers will refuse to parse your schema and any document that is associated with it.

List a Listing A - Catalog Schema

Models A Single Book in a catalog. Includes One or More Authors, One Each of Genre, Title, Price, Publish Date, and an Optional Description. a catalog of one or more books < / xs: documentation>

a collection of books

a single book List B Listing B - Catalog.xml gambardella, matthew xml developer's guide </ title> <genre> computer </ genre> <price> 44.95 </ price> <publish_date> 2000-10-01 </ public_date> <description> an in-depth look at create application with xml. </ Description> </ book> <book id = "bk102"> <author> Ralls, Kim </ author> <title> midnight rain </ title> <genre> fantasy </ genre> <price> 5.95 </ price> <public_date> 2000-12-16 <limited> <design> a former architect Battles Corporate Zombies, An Evil Sorceness, and Her Own Childhood To Become Queen of The World. </ Description> </ book> <book id = "bk103"> <author> corets, eva </ author> <title> Maeve Ascendant </ Title> <genre> Fantasy </ genre> <price> 5.95 </ price> <Publi SH_DATE> 2000-11-17 <DATE> 2000> <Description> After the collapse of a nanotechnology society in england, The Young survivors lay the foundation for a new society. </ description> </ book> </ catalog></p> <p>Now let's take a look at the XML Schema example displayed in List A, which is described in the list of book catalogs we used in List B. Listing B has a small change: Catalog as the root element has two new properties, which are associated with Catalog Schema in Listing A.</p> <p>You look at Catalog Schema, soon you will notice that it contains the standard XML head <? XML Version = "1.0"?>, This means that schema yourself is an XML document. And any Schema's root element must be Schema, which has one or more illustrates its own properties. In this case, Schema's NameSpace Define Properties (XMLns) define namespaces to XS, which will be used as root namespace of all elements in the document. -------------------------------------------------- ------------------------------</p> <p>What is the namespace XML defines the namespace to reuse after packaging XML elements. In order to use the elements defined in the namespace of the XML document, you must declare the namespace through the XMLNs property. You must also define a shortcut prefix for this name space as the root element in your document, so that the namespace can be available in the document. The prefix is ​​an identifier of any element of any imported namespace for the document. This process is like giving the library icons in Visual Basic or imported modules; the namespace under C , Java or .NET also have the same meaning.</p> <p>-------------------------------------------------- ------------------------------</p> <p>The elements of our Schema example are Annotation, which represents documents related to their parent elements. Annotation can contain one of two sub-elements, or documentation or appinfo, or both. The former is used for readable documents, while the latter is used to save instructions for supplying program processing.</p> <p>Next we defined two major elements (root elements Catalog and their sub-elements Book), they used two ELEMENT elements in their own documents. These elements contain the properties of the definition name and the content permitted by each element. In this case, the Catalog element is defined as a CatalogType type, while the BOOK element is defined as the ElementType type; these two types will be defined in the Schema document later.</p> <p>What is type?</p> <p>I have already said that XML Schema allows you to declare the elements in the XML document as a specific type, allowing the parser to check the contents of the document and its structure. XML Schem defines two main data types: predefined simple types and complex types. The main difference between these two data types is that complex types can contain other elements like data, and only data can only be included. The simple type gives XML Schema low-level type inspection capabilities, allowing you to define elements as one of the types A in Figure A.</p> <p>Simple Type Defines String String Data. Boolean binary type TRUE or FALSE. Date calendar date, format is CCYY-MM-DD. DateTime calendar date and time. Time24 hours of format can be adjusted according to time zone. Decimal's decimal number of arbitrary precision and bits. Integer integer Float standard 32-bit floating point number.</p> <p>Figure A XML Schema predefined simple type</p> <p>You can also define your own simple type. For more deep understanding of the type of XML Schema data type, please see "XML Schema Part 2: DataTypes" on the W3C website.</p> <p>Complex types are defined by the ComplexType element, which typically has at least one Name property, with index types when declaring other elements, unless it is within a certain element (see the next section). All complex types contain a content definition type, which is the main function to define the content mode that can be included. See Figure B for some available content modes.</p> <p>Complex Type Definition Sequence All elements within its definition must appear in order, and the range is specified by MinoCCURS and MaxocCurs. There is only one element in the range of CHOICE. Any of any elements defined by Any must appear. SimpleContent This complicated type contains only non-nest elements. The previously defined simple type can be expanded by including extended elements. ComplexContent This complicated type can only contain other elements. The previously defined complex type can be expanded by including extended elements. Attribute This complex type can only contain naming properties. Figure B Some permitted XML Schema complex types</p> <p>Our first complexType element in Schema defines the BookType type, you can see from the document comment element, which gives a single book construction model in the directory. BookType contains a sequence element that tells the parser This complicated type element must contain all the elements that appear in the Sequence tag in the same accurate order. For BookType, Elements Author, Title, Genre, Price and Publish_Date must appear within the booktype element.</p> <p>What is DESCRIPTION? It appears within the sequence element, is there any necessary? of course not. The Description element has a minoCCurs property that defines the minimum number of elements that can occur in complex types. In this case, the value of Minoccurs is zero, so Description is an optional element.</p> <p>This is also true of Author elements. It has a maxoccurs property, but there is no value, meaning that Author elements can appear unlimited times in Sequence, obviously, there is at least one of a book author, but not necessarily one. There is no element that doesn't have a Maxoccurs property must and can only appear once in Sequence, so all other elements in BookType Sequence are necessary and can only appear once.</p> <p>In our example, the second defined in Catalog Schema is also the last complex type is a CatalogType complex type. It also contains more than one Sequence, you can see this from the boundless maxoccurs property.</p> <p>Interpretation</p> <p>Look at your background knowledge, this article uses the example schema's structure. If you don't here, you will not only call you, the Book and Catalog elements do not use a formal complex type declaration to define Catalog Schema is also possible. This is the case. Note that the ComplexType element in the list C is nested within the ELEMENT element, and the child element of Catalog's sequence element has a REF property that tells the parser with a reference to the previously defined BOOK element.</p> <p>I have heard a lot of people like this: "Very good, if this is the case, then do you have to use these Fishermen's way?" It is very simple, we will go to illustrate the important point of XML Schema: it It is scalable. By defining the type of way you can reuse them in multiple documents, you can also extend them with different Schema, which is like reuse or extending abstract data types when developing applications.</p> <p>tool</p> <p>So far, you should realize that the syntax of XML Schema is not simple. Although Schema can be created by simple text editor, it may be called you to vomit blood. In order to better utilize it, you can use several XML tools, and some of the recent tools even provide a graphical interface that creates XML Schema. XML SPY and CAPE CLEAR Studio are all full-scale XML integrated development environments with XML Schema creation feature. DTD2XS is a DTD-TO-XML SCHEMA conversion tool that has two forms: an application and Java class running separately. Like DTD, standard XML Schema defines a lot, you can use it according to your needs in the development of applications. in conclusion</p> <p>XML Schema has the ability to force document content and structure, which is a new standard in the XML world not only important and powerful. In this article, I only explained the basic principles in this article, but I hope these elaborates will give you a basis for continued progress.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-27279.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="27279" 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.037</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 = 'h_2Bi0Dn4abncc_2BQT9fWSj_2BILd76KAckPtb4C5mFnSRL6enADEd8SVleBFuilOlDdAVoceAS27uJjwHI6xM8WhqA_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>