xml| Tutorial
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 Savei T.xml the style transformation 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------------------
! DOCTYPE movies SYSTEM "G:\\\\XMLSPY\\\\SAVEIT.DTD" >
1
Fatal Cradle
Jet Li's latest masterpiece!
2003
----------SAVEIT.DTD------------------
! 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------------------
http:/ /www.w3.org/1999/xsl/transform ">
<br>::: Lingyun XML Spy Tutorial::: <br>
movie
name |
Introduction |
time |
type |
|
|
< /xsl:value-of> |
|
Step Two: Create SAVEIT.DTD documents using XML Spy.
1) Establish the root node movies.
Select Menu File->new Pop-up Create New Document dialog box, select the DTD (document Tpye Definition), so an empty DTD document will be built in the editing area, as shown in Figure 1. Clicking the black triangle in the upper-left corner will turn into Figure 2. We will encode the item enconding the default value is UTF-8, we change it to GB2312. Double-click at Elm and enter movies. As shown in Figure 3. With the Elm movies selected, double-click sequence in the right-hand elements box, as shown in Figure 4. So the root knot movies is established.
Figure 1
Figure 2
Figure 3
Figure 4
2) Movies Add child node Id,name,brief,time and attribute type for root node.
On the movies sequence of the right key, select Add Child->element, add four child nodes for it. As shown in Figure 5. Right-click on movies Sequence, select Append->attlist, and then set its name to movies as shown in Figure 6, set name to type, set type to CDATA, and set presence to #required.
Figure 5
Figure 6
3) To establish a child node Id,name,brief,time. on the movies sequence of the right button, select Append->element, add four nodes, the data type is all set to Pcdata. As shown in Figure 7. This way, the DTD document is established. Named Saveit.dtd is saved to the G:\\\\xmlspy directory. In View->text view, you can view the source code of the Edit and select view->enhanced Grid view to return to the tree edit view.
Step three: Use XML spy to build SAVEIT.XSLT documents.
1) Select Menu File->new Eject the Create New Document dialog box, select the last XSLT (extensible Stylesheet Language) entry, and create a new XSLT file as shown in Figure 8. At this point, the XML spy automatically moves the view to the code-editing view, because it is easier to edit the XSLT directly. Change its encoding to: GB2312, as shown in Figure 9.
Figure 8
Figure 9
2) The rest of the code can be easily added to the edit area through the elements panel shown in Figure 10. After adding, set the corresponding node for each element of the attribute value to complete the XSLT document writing, the specific process is no longer detailed. As shown in Figure 11 after the completion. Named Saveit.xslt is saved to the G:\\\\xmlspy directory.
Figure 10
Figure 11
Step Fourth: Use the XML spy to build the Saveit.xml document.
1) Select Menu File->new Eject the Create New Document dialog box, select the XML document in it, and a dialog box pops up asking you to select the validation method for the XML documents as a DTD or schema, as shown in Figure 12 We chose the DTD validation method and chose the saveit.dtd that was just created as its validation document, as shown in Figure 13.
Figure 12
Figure 13
2) After clicking OK, XML Spy will automatically build an XML blank document that conforms to SAVEIT.DTD validation. 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 and select G:\\\\xmlspy\\\\saveit.xslt file in the pop-up window (shown in Figure 15) and click OK.
Figure 16
4) finished, the XML document finally edited. As shown in Figure 17. Named Saveit.xml, save to the G:\\\\xmlspy directory.
Figure 17
Fifth step: You can choose xslt->xsl Transformation or click to view the final display effect of Saveit.xml directly in the XML spy. You can also use the browser to view the G:\\\\xmlspy directory, but the browser must be more than IE6 version. If you want to output the transform results document, you can save the resulting document by changing it in the XML spy. The final display effect is shown in Figure 18. The above code is debugged through the XML Spy5.
Figure 18