How to Use XML Spy
XMLSpy is an integrated development environment for developing XML solutions. It is part of Altova's MissionKit Suite, which includes MapForce for XML data mapping and StyleVision for XML presentation layer. XMLSpy 2010 caters for every aspect of XML development. It includes an SQL interface, code comparison utility, JScript editor, debuggers, XPath evaluator, Schema generator and data conversion tools. It also has specialist tools for the WSDL, or Web Services Definition Language, and XBRL, or Extensible Business Reporting Language, specifications. It includes Altova Authentic for designing style sheets using a WYSIWYG interface. It comes with example projects and tutorials, which are for highly recommended for the beginner.
Instructions
-
-
1
Start XMLSpy. Select "File|New" from the main menu. Then select "xsd W3C XML Schema."
-
2
Enter "BookReview" in the middle of the interface where it says, "Enter name of root element here." Click on the small "Content Model View" icon, located on the same line, to the left, next to the word "element." A diagrammatic presentation of the data now will appear.
-
-
3
Right-click on BookReview and select "Add Child|Sequence." A sequence connector now appears. Right-click on the sequence connector and select "Add Child|Element." Enter "Book" in the upper space of the new box. Right-click on "Book" and select "Unbounded," so the Book data object can have multiple occurrences.
-
4
Right-click on the Book and select "Add Child|Sequence." On the new sequence connector, right-click and select "Add Child|Element," to create a new box. Repeat this five times, so that all six new boxes are connected to the same sequence under "Book."
-
5
Enter "Title" in the upper blank space of the top box. In the second, enter "Author." In the third, enter "Publisher." In the fourth, enter "Year." In the fifth, enter "ISBN." In the sixth, enter "Review."
-
6
In each of the six boxes, double-click in the blank space next to "Type" and select "xs:string," except for the "Year" box, where it should be "xs:gYear."
-
7
Select "File|Save" from the main menu. In the "Save As" dialog box, enter "C:" and press Enter. Click on the "Create New Folder" icon at the top right of the dialog box to create a new folder called "BookReview" in C:\ folder. Then in the Filename field, enter "C:\BookReview\BookReview.xsd" and select Save.
-
8
Select "DTD/Schema|Generate Sample XML File" from the main menu. In the "Generate sample XML file" dialog box, select the "Generate all elements" radio button. Enter "2" in the next box to generate two elements. Select "Generate non-mandatory attributes," "Fill elements with data" and "Assign a schema/DTD to the generated document with a relative path." Then click OK to generate the sample XML file.
When the new XML file appears, it will contain two rows of sample data.
-
9
Press F7 to verify that the XML is well formed. Press F8 to verify that the XML is data-valid. Select "File|Save As..." from the main menu, and save the file as "C:\BookReview\BookReview.xml."
-
10
Select "File|New" from the main menu, and select "xsl XSL style sheet v1.0." In the "Create new XSL/XSLT file" dialog box, select "Generic XSL/XSLT Transformation. Paste the following code between the "xsl:stylesheet" begin and end tags. Then select "File|Save As..." from the main menu, and save as file name "C:\BookReview\BookReview.xsl."
<xsl:template match="/">
<html>
<head> <title>My Book Reviews</title></head>
<body>
<h1><center>Your Company</center></h1>
<table border="1" bgcolor="yellow">
<thead align="center">
<td><strong>Title</strong></td>
<td><strong>Author</strong></td>
<td><strong>Publisher</strong></td>
<td><strong>Year</strong></td>
<td><strong>ISBN</strong></td>
<td><strong>Review</strong></td>
</thead>
<xsl:for-each select="/BookReview/Book">
<tr>
<td><xsl:value-of select="Title"/></td>
<td><xsl:value-of select="Author"/></td>
<td><xsl:value-of select="Publisher"/></td>
<td><xsl:value-of select="Year"/></td>
<td><xsl:value-of select="ISBN"/></td>
<td><xsl:value-of select="Review"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
-
11
Click on the "BookReview.xml" tab to make BookReview.xml the active document. Select "XSL/Xquery|Assign XSL..." from the main menu. Click "OK" in the message box to confirm that the XMLSpy may need to alter the XML. Then in the "XML Spy" dialog box, under "Choose a File:," enter "C:\BookReview\BookReview.xsl" and then click "OK." This will insert a reference to the XSL file inside the XML file.
-
12
Select "File|Save" to save as file name "BookReview.xml." Then press F10 to transform the "BookReview.xml" through "BookReview.xsl" to output a simple HTML Web page.
-
1
Tips & Warnings
If you want to view the HTML output through an HTML file, paste the following code into a new file at "C:\BookReview\BookReview.html" and then open BookReview.html inside a browser:
<html>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=BookReview.xml">
</head>
<body>
</body>
</html>
Resources
- Photo Credit validations sur site image by Charly from Fotolia.com