The fifth chapter: XML Instance Analytic outline: One: Instance effect two: example analysis
1. Define a new identity.
2. Create an XML document.
3. Create the corresponding HTML file. XML is widely used in different fields, such as MathML in science and technology, WML in wireless communication applications, SVG in network image, etc., we focus on the application of XML on the Web. The application of XML to the Web is mainly based on its powerful data manipulation capabilities. Generally use XML with JavaScript and ASP server-side programs, can achieve almost all the network application requirements. For the convenience of explanation, we introduce a simple example below that does not include a server-side program. The goal is to give you an intuitive understanding of the data manipulation capabilities of XML. OK, let's first [click here] to see the effect of the example. (Please open it in IE5.0 version of browser) This is a simple CD recording data retrieval function. You can see the information about a single CD by clicking on the "previous" and "Next". This effect we used to do in two ways: 1. Using DHTML, the data is hidden in different layers and displayed in sequence by mouse events; 2. Use background programs (such as asp,cgi,php,jsp, etc.) to invoke server-side data. But in this case, we open the page's original code and see that there is no DHTML Div, no action on the form, it's completely XML. Let's analyze its production process: the first step: defining a new identity.
According to the actual CD data, first create a new logo named <CD>, and then establish its related data identification, respectively: CD name <title>, singer <artist>, publishing age <year>, country < Country>, issuing company <Company> and price <Price>; Finally, a logo named directory <CATALOG> will be established. Why build a <CATALOG> logo again? Because the XML document stipulates that there must and can only be one root element (identity), we have multiple CD data, which is a side-by-side relationship, so we need to create a root element for these parallel elements.
The definitions and relationships of the above elements are fully compliant with the XML standard and do not require a special DTD file to define, so you can omit the DTD definition. If we want to use DTDs to define, the above procedure can be expressed as:
<! ELEMENT CATALOG (CD) *>
<! ELEMENT CD (Title,artist,year,country,company,price) >
<! ELEMENT Title (#PCDATA) >
<! ELEMENT Artist (#PCDATA) >
<! ELEMENT year (#PCDATA) >
<! ELEMENT Country (#PCDATA) >
<! ELEMENT Company (#PCDATA) >
<! ELEMENT Price (#PCDATA) >
This code indicates that the element catalog contains multiple CD child elements, and the child element CD contains the title, Artist, year, Country, company, and price six child elements, all of which are defined as text (characters, numbers, text). (Note: A specific syntax note can look at a chapter on the introduction to DTDs) Step two: Create an XML document.
The above code first uses the <?xml version= "1.0"?> declaration statement to indicate that this is an XML document, and its format complies with the XML 1.0 standard specification. Then the document content, the structure tree is very clear:
<CATALOG>
<CD>
......
</CD>
<CD>
......
</CD>
</CATALOG>
5 sets of data are defined altogether. We save the above code as a cd.xml file for the call. Step three: Create the corresponding HTML file.
1. Import XML data.
We know that in the current popular browsers, only Microsoft's IE5.0 version of the browser supports XML for the time being. IE supports inserting XML by object object in HTML, and imports data through the XmlDocument.Load () method of JS. Let's look at the code:
2. Bundle of data.
The XML data is then bound to the table using the <SPAN> identity. Where id,datasrc,dtatfld are the properties of <SPAN>. The code is as follows:
Save the above code as a cd.htm file and put it together in the second step of the Cd.xml file. Open the Cd.htm file and you'll see the same effect as the example above.
Well, so far, we've learned a lot about XML, so let's summarize the first five chapters, which are XML QuickStart, the concept of XML, XML terminology, XML syntax, and example parsing in this chapter. Here, the tutorial section is over. In the process of writing, Atzie do our best to the concept of XML to speak easily understandable, as far as possible their understanding to tell everyone, but because I learn XML time is not long, the entire XML technology is not enough to grasp the system and in-depth, so it is inevitable that there are omissions, please correct and understanding, thank you!
At the end of the tutorial, it comes with a chapter "XML Related Resources", which provides a number of very good learning sites and resource connections that are recommended for you to save. Please continue browsing: XML related resources.
(Source: Enet College)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.