search
HomeBackend DevelopmentXML/RSS TutorialDetailed explanation of XML Spy example code (picture)

Before reading this tutorial, you should at least make sure that you are familiar with XML, have edited XML, DTD and XSLT documents using Notepad or other tools, and are familiar with their Grammar and usage, otherwise please make up the lesson before reading this tutorial.

XML Spy is an editor developed by Icon Information System that supports XML, XSL, XSLT, DTD, Schema and other file formats. It can display XML as a perfect tree structure, and can easily use various HTML/XML/XSLT tags. Using it can greatly save our development time, and we do not have to waste a lot of time on code input. Let's learn how to use XML Spy through an example of storing movie information.

Step one: We need to design three files: saveit.xml, saveit.dtd and saveit.xslt; saveit.xml is responsible for storing specific movie content data, and saveit.dtd is responsible for verifying saveit.xml. Saveit.xslt is responsible for style transformation of saveit.xml and determines its final display effect in the browser. Let’s first look at the code of the three files we need to create:

----------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="动作片">
<id>1</id>
<name>致命摇篮</name>
<brief>李连杰最新力作!</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="/">
<html>
<head>
<title>
:::凌云的XML Spy教程:::
</title>
</head>
<body>
<xsl:apply-templates></xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="movies">
第<xsl:value-of select="id"></xsl:value-of>部电影
<table>
<tbody>
<tr>
<td>名称</td>
<td>简介</td>
<td>时间</td>
<td>类型</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>

Step 2: Use XML Spy to create the saveit.dtd document.

1) Establish the root node movies

​Select the menu File->New to pop up the Create new document dialog box, select the dtd (Document Type Definition) inside, so that an empty DTD document will is established in the editing area, as shown in Figure 1. Click the black triangle in the upper left corner and it will look like Figure 2. We set the encoding method item encoding default value to UTF-8, and we changed it to GB2312. Double-click on Elm and enter movies. After completion, as shown in Figure 3. Keep Elm movies selectedstate, double-click the sequence of in the Elements box on the right, the result is shown in Figure 4. In this way, the root node movies is established.

Detailed explanation of XML Spy example code (picture)
Picture 1

Detailed explanation of XML Spy example code (picture)
Picture 2

Detailed explanation of XML Spy example code (picture)
Picture 3

Detailed explanation of XML Spy example code (picture)
Figure 4

2) Add child node id, name, brief, time and attribute type for the root node movies.

Right-click on the movies sequence of and select Add child ->ELEMENT, add four child nodes to it. As shown in Figure 5. Right-click on the movies sequence of again, select Append->ATTLIST, and then set its name to movies, set Name to type, set Type to CDATA, and set Presence to #REQUIRED as shown in Figure 6 .

Detailed explanation of XML Spy example code (picture)
Figure 5

Detailed explanation of XML Spy example code (picture)
Figure 6

3) Create sub-nodes id, name, brief, time. In movies Right-click on the sequence of, select Append->ELEMENT, add four nodes, and set all data types to PCDATA. As shown in Figure 7. In this way, the DTD document is created. Name it saveit.dtd and save it to the G:////xmlspy directory. In View->Text view mode, you can view the source code obtained by editing. Selecting View->Enhanced Grid view will return to tree editing View mode.

Detailed explanation of XML Spy example code (picture)

Step 3: Use XML Spy to create the saveit.xslt document.

1) Select the menu File->New to pop up the Create new document dialog box, select the last item xslt (Extensible Stylesheet Language), and create a new xslt file as shown in Figure 8 Show. At this time, XML Spy will automatically transfer the view to the code editing view, because it is more convenient to edit xslt directly. Change its encoding method to: GB2312, as shown in Figure 9.

Detailed explanation of XML Spy example code (picture)
Picture 8

Detailed explanation of XML Spy example code (picture)
Picture 9

2) The rest of the code can be easily added to the editing area through the Elements panel shown in Figure 10. After the addition is completed, set the corresponding nodes to the attribute values ​​of each element to complete the writing of the XSLT document. The specific process will not be detailed. After completion, it will look like Figure 11. Name it saveit.xslt and save it to the G:////xmlspy directory.

Detailed explanation of XML Spy example code (picture)
Picture 10

Detailed explanation of XML Spy example code (picture)
Picture 11

Step 4: Use XML Spy to create the saveit.xml document.

1) Select the menu File->New to pop up the Create new document dialog box, select xml (XML Document) inside, and a dialog box will pop up asking you to choose whether the XML document verification method is DTD or Schema. As shown in Figure 12, we select the DTD verification method and select the saveit.dtd just created as its verification document, as shown in Figure 13.

Detailed explanation of XML Spy example code (picture)
Figure 12

Detailed explanation of XML Spy example code (picture)
Figure 13

​ ​ ​ 2) After clicking OK, XML Spy will automatically build a saveit for us .dtd validated XML blank document. As shown in Figure 14. Fill in the content data. Change the encoding method item encoding to GB2312. The result is shown in Figure 15.

Detailed explanation of XML Spy example code (picture)
Figure 14

Detailed explanation of XML Spy example code (picture)
Figure 15

​ ​ 3) Select the XSL->Assign XSL menu, and select As shown in Figure 15), select the G:////xmlspy////saveit.xslt file and click OK.

Detailed explanation of XML Spy example code (picture)
Figure 16

4) You’re done, The XML document is finally edited. As shown in Figure 17. Name it saveit.xml and save it to the G:////xmlspy directory.

Detailed explanation of XML Spy example code (picture)
Figure 17

Step 5: You can select XSLT->XSL Transformation or click to view the final display effect of saveit.xml directly in XML Spy. You can also go to the G:////xmlspy directory and use a browser to watch it, but the browser must be IE6 or above. If you want to output the transformation result document, you can click to save the result document after transformation in XML Spy. The final display effect is shown in Figure 18. The above code passes Debugging in XML Spy5.

Detailed explanation of XML Spy example code (picture)
Picture 18

The above is the detailed content of Detailed explanation of XML Spy example code (picture). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
RSS in XML: Unveiling the Core of Content SyndicationRSS in XML: Unveiling the Core of Content SyndicationApr 22, 2025 am 12:08 AM

The implementation of RSS in XML is to organize content through a structured XML format. 1) RSS uses XML as the data exchange format, including elements such as channel information and project list. 2) When generating RSS files, content must be organized according to specifications and published to the server for subscription. 3) RSS files can be subscribed through a reader or plug-in to automatically update the content.

Beyond the Basics: Advanced RSS Document FeaturesBeyond the Basics: Advanced RSS Document FeaturesApr 21, 2025 am 12:03 AM

Advanced features of RSS include content namespaces, extension modules, and conditional subscriptions. 1) Content namespace extends RSS functionality, 2) Extended modules such as DublinCore or iTunes to add metadata, 3) Conditional subscription filters entries based on specific conditions. These functions are implemented by adding XML elements and attributes to improve information acquisition efficiency.

The XML Backbone: How RSS Feeds are StructuredThe XML Backbone: How RSS Feeds are StructuredApr 20, 2025 am 12:02 AM

RSSfeedsuseXMLtostructurecontentupdates.1)XMLprovidesahierarchicalstructurefordata.2)Theelementdefinesthefeed'sidentityandcontainselements.3)elementsrepresentindividualcontentpieces.4)RSSisextensible,allowingcustomelements.5)Bestpracticesincludeusing

RSS & XML: Understanding the Dynamic Duo of Web ContentRSS & XML: Understanding the Dynamic Duo of Web ContentApr 19, 2025 am 12:03 AM

RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS Documents: The Foundation of Web SyndicationRSS Documents: The Foundation of Web SyndicationApr 18, 2025 am 12:04 AM

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

Decoding RSS: The XML Structure of Content FeedsDecoding RSS: The XML Structure of Content FeedsApr 17, 2025 am 12:09 AM

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

How to Parse and Utilize XML-Based RSS FeedsHow to Parse and Utilize XML-Based RSS FeedsApr 16, 2025 am 12:05 AM

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS Documents: How They Deliver Your Favorite ContentRSS Documents: How They Deliver Your Favorite ContentApr 15, 2025 am 12:01 AM

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.