《软件工程毕业论文外文文献—XML概述》由会员分享,可在线阅读,更多相关《软件工程毕业论文外文文献—XML概述(12页珍藏版)》请在金锄头文库上搜索。
1、外文原文Introducing XMLYou have seen several examples (for instance, in Chapters 4 and 10) of the use of property files to describe the configuration of a program. A property file contains a set of name/value pairs, such as fontname=Times Roman fontsize=12 windowsize=400 200 color=0 50 100You can use th
2、e Properties class to read in such a file with a single method call. Thats a nice feature, but it doesnt really go far enough. In many cases, the information that you want to describe has more structure than the property file format can comfortably handle. Consider the fontname/fontsize entries in t
3、he example. It would be more object oriented to have a single entry:font=Times Roman 12But then parsing the font description gets uglyyou have to figure out when the font name ends and when the font size starts.Property files have a single flat hierarchy. You can often see programmers work around th
4、at limitation with key names such astitle.fontname=Helveticatitle.fontsize=36body.fontname=Times Romanbody.fontsize=12Another shortcoming of the property file format is caused by the requirement that keys be unique. To store a sequence of values, you need another workaround, such asmenu.item.1=Times
5、 Romanmenu.item.2=Helveticamenu.item.3=Goudy Old StyleThe XML format solves these problems because it can express hierarchical structures and thus is more flexible than the flat table structure of a property file.An XML file for describing a program configuration might look like this: Helvetica 36 T
6、imes Roman 12 400 200 0 50 100 Times Roman Helvetica Goudy Old Style The XML format allows you to express the structure hierarchy and repeated elements without contortions.As you can see, the format of an XML file is straightforward. It looks similar to an HTML file. There is a good reasonboth the X
7、ML and HTML formats are descendants of the venerable Standard Generalized Markup Language (SGML).SGML has been around since the 1970s for describing the structure of complex documents. It has been used with good success in some industries that require ongoing maintenance of massive documentation, in
8、 particular, the aircraft industry. However, SGML is quite complex, so it has never caught on in a big way. Much of that complexity arises because SGML has two conflicting goals. SGML wants to make sure that documents are formed according to the rules for their document type, but it also wants to ma
9、ke data entry easy by allowing shortcuts that reduce typing. XML was designed as a simplified version of SGML for use on the Internet. As is often true, simpler is better, and XML has enjoyed the immediate and enthusiastic reception that has eluded SGML for so long.NOTEYou can find a very nice versi
10、on of the XML standard, with annotations by Tim Bray, at http:/ though XML and HTML have common roots, there are important differences between the two.Unlike HTML, XML is case sensitive. For example, and are different XML tags.In HTML, you can omit end tags such as or tags if it is clear from the co
11、ntext where a paragraph or list item ends. In XML, you can never omit an end tag.In XML, elements that have a single tag without a matching end tag must end in a /, as in . That way, the parser knows not to look for a tag.In XML, attribute values must be enclosed in quotation marks. In HTML, quotati
12、on marks are optional. For example, is legal HTML but not legal XML. In XML, you would have to use quotation marks: width=300.In HTML, you can have attribute names without values, such as . In XML, all attributes must have values, such as checked=true or (ugh) checked=checked.NOTEThe current recomme
13、ndation for web documents by the World Wide Web Consortium (W3C) is the XHTML standard, which tightens up the HTML standard to be XML compliant. You can find a copy of the XHTML standard at http:/www.w3.org/TR/xhtml1/. XHTML is backward-compatible with current browsers, but unfortunately many current HTML authoring tools do not yet support it. Once XHTML becomes more widespread, you can use the XML tools that are described in this chapter to analyze web documents.The Structure of an XML DocumentAn XML document should start with a header such asorStrictly speaking, a heade