Chapter 5: XML Instance Analysis Outline: 1: Example Effects 2: Instance Analysis 1. Define the new identity. 2. Establish an XML document. 3. Establish a corresponding HTML file. XML has a wide range of applications in different fields, such as Mathml, wireless communication applications in technology, SVG in network images, etc., we focus on the application of XML on the Web. The application of XML on the web is mainly used with its powerful data operation capabilities. Generally use server-side program such as JavaScript and ASP to implement almost all applications on the network. Consider explaining convenience, we will introduce a simple example below and does not include server-side programs. The purpose is to let you have a sensibility to XML's data operation capacity. Ok, we first [click here] to see the effects of the instance. (Please open with IE5.0 or later) This is a simple CD record data search function. You can see the information about the single CD by clicking "Previous", "Next". Such an effects can be implemented in two ways: 1. Take DHTML, hide data in different layers, sequentially displayed by mouse events; 2. Use background programs (such as ASP, CGI, PHP, JSP, etc.), call Server data. But in this example, we open the page original code, where there is no DIV of DHTML, there is no form of action, which is fully implemented with XML. Let's analyze its production process: Step 1: Define new logos. According to the actual CD data, first create an identifier named ; secondly build it related data identity, namely: CD name , singer , publishing Year , national , Issued company and price ; finally establish an identity named catalog . Why build a ID again? Because in the XML document, you must have a root element (identifier), we have multiple CD data, which is parallel, so you need to establish a root element for these side. The definitions and relationships of the above elements are fully compliant, and the DTD definition can be omitted without the special DTD files. If we want to use DTD to define, the above process can be represented as: This code is represented: Element Catalog contains multiple CD child elements, while sub-element CDs contain Title, Artist, Year, Country, Company, Price six sub-elements, and their content is defined as text (characters, numbers, text). (Note: The specific grammatical description can look at the introduction of DTD) Step 2: Establish an XML document.
XML Version = "1.0"?> Empire Burlesque title> Bob Dylan Artist> USA country> Columbia company> 10.90 price> 1985 year> cd> hide your heart title> Bonnie Tylor artist> UK country> CBS Records company> 9.90 price> 1988 year> cd> greatest hits title> Dolly Parton artist> USA country> RCA company> 9.90 price> 1982 year> cd> still got the blues title> Gary More Artist> UK country> Virgin redords company> 10.20 price> 1990 year> cd> < Title> Eros Title> Eros Ramazzotti Artist> Eu country> BMG company> 9.90 price> 1997 year> CD> catalog> The above code first uses XML Version = "1.0"?> Declarative statement indicates that this is an XML document, its format complies with the XML 1.0 standard specification. Then the document content, the structure tree is very clear: ... < ... < cd> catalog> defines 5 sets of data. We will save the above code as a CD.xml file for an order.
Step 3: Establish a corresponding HTML file. 1. Import XML data. We know that in the current popular browser, we temporarily only have Microsoft IE5.0 or higher browser support XML. IE is imported into the Object object in HTML and is imported into the XML and through the XMLDocument.Load () method of JS. We look at the code: