Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of XML Spy

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shares with you the content of the sample analysis of XML Spy. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

XML Spy is an editor developed by Icon Information System that supports multiple file formats such as XML,XSL,XSLT,DTD,Schema. It can show XML as a perfect tree structure, can easily use a variety of HTML/XML/XSLT tags, using it can greatly save our development time, 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.

The first step: we need to design three files: saveit.xml,saveit.dtd and saveit.xslt;saveit.xml are responsible for storing specific movie content data, saveit.dtd is responsible for verifying the saveit.xml, and saveit.xslt is responsible for changing the style of saveit.xml to determine its final display effect in the browser. Let's take a look at the code for the three files we need to create:

-saveit.xml- < movies type= "Action Film" > < id > 1 < / id > < name > fatal Cradle < / name > < brief > Jet Li's latest masterpiece! < / brief > < time > 2003 < / time > < / movies >-saveit.dtd- -saveit.xslt- < 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 >: < / title > < / head > < body > < xsl:apply-templates > < / xsl:apply-templates > < / body > < / html > < / xsl:template > < xsl:template match=" movies "> < xsl:value-of select=" Id "> < 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 >

Step 2: create an saveit.dtd document using XML Spy.

1) establish the root node movies

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

Figure 1

Figure 2

Figure 3

Figure 4

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

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

Figure 5

Figure 6

3) create a child node id,name,brief,time. Right-click on movies sequence of, select Append- > ELEMENT, add four nodes, and set the data type to PCDATA. As shown in figure 7. In this way, the DTD document is established. Name it saveit.dtd and save it to the G:////xmlspy directory. You can view the source code obtained by editing in View- > Text view mode, and select View- > Enhanced Grid view to return to the tree editing view.

Step 3: create an saveit.xslt document using XML Spy.

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

Figure 8

Figure 9

2) the rest of the code can be easily added to the editing area through the Elements panel shown in figure 10. After adding, set the corresponding node to the attribute value of each element to complete the preparation of the XSLT document, the specific process will not be described in detail. After completion, it is shown in figure 11. Name it saveit.xslt and save it to the G:////xmlspy directory.

Figure 10

Figure 11

Step 4: create an saveit.xml document using XML Spy.

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

Figure 12

Figure 13

2) after clicking OK, XML Spy will automatically build a blank XML document that meets the saveit.dtd verification for us. As shown in figure 14. Fill in the content data. Change the encoding item enconding to GB2312. The result is shown in figure 15.

Figure 14

Figure 15

3) Select the XSL- > Assign XSL menu, select the G:////xmlspy////saveit.xslt file in the pop-up window (shown in figure 15), and click OK.

Figure 16

4) it's done, and the XML document is finally edited. As shown in figure 17. Name it saveit.xml and save it to the G:////xmlspy directory.

Figure 17

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

Figure 18

Thank you for reading! This is the end of this article on "sample Analysis of XML Spy". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report