![]() |
|
||||||||||||||
| | 网站首页 | 数据库教程 | web编程 | 服务器 | 程序设计 | | ||
|
||
|
||||||||||||||||||||||||||||||||||||||||
| XML解析开发指南 | ||||||||||||||||||||||||||||||||||||||||
作者:佚名 文章来源:不详 点击数: 更新时间:2007-9-2 ![]() |
||||||||||||||||||||||||||||||||||||||||
|
XML解析开发指南 1 修改历史
2 介绍本文是基于XML开发相关内容。 我相信,掌握学习方法比没有秩序的学习要重要的多。因此,在文章每一部分,对于重要的地方、或者是比较难理解的地方,结合自己的实际开发,提出了一些心得。包括:学习的内容、进步的过程等。给出了翔实的例子,并添加注释。 3 基本概念XML (Extensible Markup Language) is a flexible way to create common information formats and share both the format and the data on the World Wide Web, intranets, and elsewhere. XML can be used by any individual or group of individuals or companies that wants to share information in a consistent way. XML, a formal recommendation from the World Wide Web Consortium (W3C), is similar to the language of today's Web pages, the Hypertext Markup Language (HTML). Both XML and HTML contain markup symbols to describe the contents of a page or file. HTML, however, describes the content of a Web page (mainly text and graphic images) only in terms of how it is to be displayed and interacted with. For example, a <P> starts a new paragraph. XML describes the content in terms of what data is being described. For example, a <PHONENUM> could indicate that the data that followed it was a phone number. This means that an XML file can be processed purely as data by a program or it can be stored with similar data on another computer or, like an HTML file, that it can be displayed. For example, depending on how the application in the receiving computer wanted to handle the phone number, it could be stored, displayed, or dialed 3.1 XMLØ eXtensible Markup Language Ø XML is a meta-language, you create tags by yourself. Ø XML was derived from Standard Generalized Markup Language, SGML(Standard Generalized Markup Language). Ø XML is only a markup language , but use it we can write applications in such aspects: web sites, electronic data interchange, vector graphics, genealogy, real-estate listings, object serialization, remote procedure calls, voice-mail systems, and more. Ø XML is a creation of the World Wide Web Consortium (W 3.2 Why XML?Ø Data and divsentation can be separated. Ø So the developer will put more concerns on data, but not how to display them. Ø Exchanging Data is more flexible. n XML can be stored as text, it is independent of platforms. Ø Used widely in the B2B business model Ø Many databases support XML , you can import or export data to or from the databases. Ø XML can be used to Create new Languages, such as WML(Wireless Markup Language). 3.3 What is XML?Ø Simple text formatted to follow a well-defined set of rules Ø XML documents consist primarily of tags and text, familiar with HTML document. Ø The tags define keys that have text values and may contain data on any topic, that is, name-value pairs.Example: City = Ø This text may be stored/redivsented in: n A normal file stored on disk. n A message being sent over HTTP. n A character string in a programming language. n A text BLOB (binary large object) in a database. n Any other way textual data can be used. 3.4 XML Family Overview3.5 XSLXSL is a family of recommendations for defining XML document transformation and divsentation. It consists of three parts: XSL Transformations (XSLT) a language for transforming XML the XML Path Language (XPath) an exdivssion language used by XSLT to access or refer to parts of an XML document. (XPath is also used by the XML Linking specification) XSL Formatting Objects (XSL-FO) an XML vocabulary for specifying formatting semantics An XSLT stylesheet specifies the divsentation of a class of XML documents by describing how an instance of the class is transformed into an XML document that uses a formatting vocabulary, such as (X)HTML or XSL-FO. For a more detailed explanation of how XSL works, see the What Is XSL page. For background information on style sheets, see the Web style sheets resource page. XSL is developed by the W 3.5.1 XSLTThe XSL Transformations (XSLT) describes a language for transforming XML documents into other XML documents or other text output. It was defined by the W The XSLT 1.0 Recommendation is located at: http://www.w3.org/TR/1999/REC-xslt-19991116 4 XPATH4.1 介绍4.1.1 AbstractXPath is a language for addressing parts of an XML document, designed to be used by both XSLT and XPointer. XPath 2.0 is an exdivssion language that allows the processing of values conforming to the data model defined in [XQuery/XPath Data Model (XDM)]. The data model provides a tree redivsentation of XML documents as well as atomic values such as integers, strings, and booleans, and sequences that may contain both references to nodes in an XML document and atomic values. The result of an XPath exdivssion may be a selection of nodes from the input documents, or an atomic value, or more generally, any sequence allowed by the data model. The name of the language derives from its most distinctive feature, the path exdivssion, which provides a means of hierarchic addressing of the nodes in an XML tree. XPath 2.0 is a superset of [XPath 1.0], with the added capability to support a richer set of data types, and to take advantage of the type information that becomes available when documents are validated using XML Schema. A backwards compatibility mode is provided to ensure that nearly all XPath 1.0 exdivssions continue to deliver the same result with XPath 2.0; exceptions to this policy are noted in [I Backwards Compatibility with XPath 1.0]. 4.1.2 Abbreviated SyntaxHere are some examples of location paths using abbreviated syntax: · · · · · · · · · · · · · · · · · · · · · · The most important abbreviation is that There is also an abbreviation for attributes:
NOTE: The location path A location step of self::node()/descendant-or-self::node()/child::para and so will select all Similarly, a location step of 4.1.3 Abbreviations注意:如果级联多层(多于两层),也要把参数设置为://
4.2 使用心得1. 这些缩写经常组合起来使用。 2. 灵活的使用常用这些缩写,可以大大提高开发效率。 3. 没有必要记住所有的缩写,需要时,可以查询一下手册。 4. 但是要记住最常用的使用。每次查询手册也是非常耗时间的。提高你的开发速度和成就感。 4.3 XPath操作实例这里采用dom4j工具对xpath语法的使用进行举例说明 。 4.3.1 | ||||||||||||||||||||||||||||||||||||||||
| //BBB[@name='bbb'] |
| |