XML Spy Instance Tutorial

Source: Internet
Author: User
Tags xsl xslt

Before you read this tutorial, you should at least make sure that you are familiar with XML, edited XML, DTDs, and XSLT documents using Notepad or other tools, and are familiar with their syntax and purpose, otherwise you can read this tutorial after you have finished your class.

XML Spy is an editor developed by icon Information System that supports Xml,xsl,xslt,dtd,schema and many other file formats. It can show XML as a perfect tree structure, can easily use a variety of html/xml/xslt tags, use it can greatly save our development time, do not have to waste a lot of time on the input of the code. Let's learn how to use XML spy with an example of storing movie information.

The first step: we want to design three files: Saveit.xml,saveit.dtd and Saveit.xslt;saveit.xml are responsible for storing specific film content data, SAVEIT.DTD is responsible for saveit.xml validation, and SAVEIT.XSLT is responsible for SaveIt . xml transforms the style to determine its final display in the browser. Let's take a look at the code for the three files we need to build:

----------Saveit.xml------------------
<?xml version= "1.0" encoding= "GB2312"?
! DOCTYPE movies SYSTEM "G:\XMLSPY\SAVEIT.DTD" >
<?xml-stylesheet type= "text/xsl" href= "G:\xmlspy\saveit.xslt"?
<movies type= "action film"
<id> 1 </id>
<name> Fatal Cradle </name>
<brief> Jet Li's latest masterpiece! </brief>
<time> 2003 </time>
</movies>
----------SAVEIT.DTD------------------
<?xml version= "1.0" encoding= "GB2312"?
! ELEMENT Movies (ID, name, brief, time)
! attlist Movies Type CDATA #REQUIRED >
! ELEMENT ID (#PCDATA) >
! ELEMENT name (#PCDATA) >
! ELEMENT Brief (#PCDATA) >
! ELEMENT Time (#PCDATA) >
----------Saveit.xslt------------------
<?xml version= "1.0" encoding= "UTF-8"?
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform"
<xsl:output method= "xml" version= "1.0" encoding= "GB2312" indent= "yes"/>
<xsl:template match= "/" >
<title>
::: Lingyun's XML Spy tutorials:::
</title>
<body>
<xsl:apply-templates> </xsl:apply-templates>
</body>
</xsl:template>
<xsl:template match= "Movies"
Section <xsl:value-of select= "id" > </xsl:value-of> movie
<table>
<tbody>
<tr>
<td> name </td>
<td> Introduction </td>
<td> Time </td>
<td> type </td>
</tr>
<tr>
<td> <xsl:value-of select= "name" </xsl:value-of> </td>
<td> <xsl:value-of select= "brief" > </xsl:value-of> </td>
<td> <xsl:value-of select= "Time" </xsl:value-of> </td>
<td> <xsl:value-of select= "@type" > </xsl:value-of> </td>
</tr>
</tbody>
</table>
</xsl:template>
</xsl:stylesheet>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.