Application of Name Space in XML (Original)

xiaoxiao2021-03-06  77

Application of Name Space in XML

We may have written this simple XML document:

Professor </ Title></p> <p><Name> Teacher Zhang </ Name></p> <p><Phone> 98989988 </ phone></p> <p></ Teacher></p> <p></ Data Structure Course></p> <p>We can find that the above XML document element is relatively simple, and the structure is relatively simple, it is better to achieve, but when we want to make this structure more more complex, if you add this to this school When this class, which is the class, etc., I have to solve the element by adding elements, so it is necessary to increase the hierarchical structure. It is very inconvenient. So what is the way to solve this problem?</p> <p>The answer is that we can solve this problem through the namespace.</p> <p>So maybe someone will ask: "What is the name space?". The English name of the name space is NameSpace, and the as the name is to allow you to identify your label through a URL. E.g:</p> <p><University: Teacher XMLns: University = "http://www.beihang.com"></p> <p>Where XMLNs is an abbreviation of XHTML Namespace, called "Name Space" declaration.</p> <p>Why use the namespace? Because we all know that XML is allowed to customize the label, so it is possible that the label we define is the same, but the meaning of the representation may be different. Errors are easily generated when file exchange or sharing.</p> <p>For example, Zhang San and Li Si defined a "label of school>, Zhang San's" school "tag refers to Beihang, Li Si's <School> Tag refers to Western Western, then when two documents exchange data, It is unable to distinguish this <School> The label refers to the Western Stadium or Beihang, which will have problems. In order to avoid this error, XML uses a namespace statement, allowing you to identify your label through a URL. For example, Zhang San's <School> The namespace of the label is "http://www.beihang.com", Li Si's <School> Label Name Space is "http://www.xigongda.com".</p> <p>So how do you implement the following XML documentation through the namespace?</p> <p><? XML Version = "1.0" encoding = "GB2312"?></p> <p><University: Teacher XMLns: University = "http://www.beihang.com"></p> <p><Teacher: Data Structure Course XMLns: Teacher = "http://www.beihang.com/computer/zhang"></p> <p><Teacher: Title> Professor </ Teacher: Titles></p> <p><Teacher: Name> Teacher Zhang </ Teacher: Name></p> <p><Teacher: Phone> 98989988 </ Teacher: Telephone></p> <p></ Teacher: Data Structure Course></p> <p></ University: Teacher></p> <p>The source program is as follows:</p> <p>Package XML_Study;</p> <p>Import Org.jdom. *;</p> <p>Import org.jdom.output.xmloutputter;</p> <p>Import java.math.biginteger;</p> <p>Import java.io.ioException;</p> <p>Public class prefixedfibonacci {</p> <p>Public prefixedfibonacci () {</p> <p>}</p> <p>Public static void main (String [] args) {</p> <p>Element root = new element ("teacher", "university", "http://www.beihang.com");</p> <p>// Refers to the teacher of Beihang</p> <p>Element Mrow = New Element ("Data Structure Course", "Teacher", "http://www.beihang.com/computer/zhang"); // Refers to Zhang Teacher Zhang, North Airlines</p> <p>Element mi = new element ("title", "teacher", "http://www.beihang.com/computer/zhang");</p> <p>Mi.Settext ("Professor");</p> <p>MROW.ADDCONTENT (MI);</p> <p>Element Mo = New Element ("Name", "Teacher", "http://www.beihang.com/computer/zhang");</p> <p>Mo.setText ("Teacher Zhang");</p> <p>MROW.ADDCONTENT (MO);</p> <p>Element mm = new element ("Phone", "Teacher", "http://www.beihang.com/computer/zhang");</p> <p>Mm.Settext ("98989988");</p> <p>Mrow.AddContent (mm);</p> <p>Root.addContent (MROW);</p> <p>Document Doc = New Document (root);</p> <p>Try {</p> <p>XMloutPutter Serializer = New Xmloutputter (", TRUE);</p> <p>Serializer.setencoding ("GB2312");</p> <p>Serializer.Output (DOC, System.out);</p> <p>}</p> <p>Catch (IOException E) {</p> <p>System.err.Print (e);</p> <p>}</p> <p>}</p> <p>}</p> <p>The program succeeded in JBuilder9 and Tomcat4.0.</p> <p>The basic JDOM rules for the namespace are: When the element or attribute is in the namespace instead of specifying a fully qualified name, you must specify local name, prefix, and URI in turn. If the element is in the default namespace, the prefix is ​​omitted.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-108697.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="108697" 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.038</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 = 'Wp60xj_2FVG7wINIdQb2q_2FM2cY5ypa3TbM9oOhG0MvyY17LlcE1HMD2fNJiOfAYganm2bzbeKfhGdMICpoyHpLGg_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>