• No results found

INTRO TO XMLSPY (IXS)

N/A
N/A
Protected

Academic year: 2021

Share "INTRO TO XMLSPY (IXS)"

Copied!
60
0
0

Loading.... (view fulltext now)

Full text

(1)

INTRO TO XMLSPY (IXS)

Student Notebook

(2)

Table of Contents

Example Files ...4

Introduction ...5

Course Objectives ...6

Three Parts of XMLSpy’s Main Window ...7

The Editing Views ...8

The Technology ...9

Creating a New Document...10

Making & Storing Your Own Templates...11

Creating an Instance Document from a Schema ...12

Creating an Instance Document from a Schema-(cont’d) ...13

Context Sensitive Entry Helper Windows ...15

Context Sensitive Entry Helper Windows ...16

Context Sensitive Entry Helper Windows ...17

Well-Formedness and Validation Checking ...18

Grid View Editing XML Documents...20

Generating Instance From Schema ...22

Differencing Tool...23

Generate a Schema from an Instance Document...24

Creating a Schema: Text & Schema/WSDL View...24

Editing in Schema/WSDL View...27

Generate Documentation from a Schema ...30

Generating Program Code from a Schema ...31

Generate Java code from Schema ...32

Import Database Data (XML Document)...33

XML |TABLE Feature Revisited ...36

XPath, XSLT Debugging and Transformation...37

XPath...37

XPath Generator...38

XPath Evaluator...38

XSLT...41

XSLT Engines...42

Debugging ...44

Debugger Windows ...45

Debugger Tools ...47

Other XSLT Commands & Toolbar Icons ...50

Project Window...51

XMLSpy’s Additional Features ...60

(3)

Intro to XMLSpy – Product Training

Target Audience: (a) Software Developers/Data Integration specialists (b) People new to XML technologies willing to do a little

pre-work to prepare them for understanding the benefits of using XMLSpy with learning the technologies.

What the course is: Intro to XMLSpy will introduce you to the features of XMLSpy that will expedite your development and data integration projects. It’s XMLSpy product training.

What the course is not: It’s not basic XML. To appreciate an introductory amount of what XMLSpy can do, you will need to have at least a basic understanding of XML technologies.

Pre-work: For those new to XML Technologies, you will need to have a general understanding of the definitions of the XML

Technologies and terms listed below. Consult the resources listed here for your research.

Sources: http://www.altova.com/reference_tool.html

http://www.altova.com/dev_portal.html http://www.w3schools.com

Terms & Technologies

• XML – eXtensible markup language

• XSD – eXtensible schema development language

• XSL – eXtensible stylesheet language

• XSLT – eXtensible stylesheet transformation language

• XPath – eXtensible path language

• Well-formedness

• Validation

(4)

Example Files

Example files included in this package: VirtualRecipe.xml VirtualRecipe.xsd VirtualRecipe.xslt VirtualRecipe.html

DevgoodChocolatesProducts.mdb

(5)

Introduction

Secret Agent Niki Devgood

The picture you see on your screen is Niki Devgood – She’s secret agent, Niki Devgood. You’ve probably seen her in our ad

campaigns. Her characteristics represent our entire Altova product line:

She’s…

• got technical expertise;

• adept at data collection and reporting;

• proficient in numerous languages and dialects;

• a skilled presenter;

• always improving and she

• gets to the information behind the information;

• and she integrates well!

So, XMLSpy isn’t spy ware as some may initially think - it’s an integrated Development Environment (IDE) for the evolution of XML projects. With its wide range of features, where does one begin learning a product like XMLSpy? Well, it depends on the project you are handed.

Today, we are going to start by learning how to navigate the graphical user interface. Then, through a series of exercises, we’re going to walk you through how to use the main features of XMLSpy as they relate to specific XML technologies or eXtensible Markup Language

technologies like:

• XML

• XSD

• XSL

• XSLT

• XPath

The examples we are going to use are built around a case study of the Devgood Chocolate Company. (It’s really a field office for the Agency to which Niki reports – but don’t tell anybody.) The “company” is in the midst of a rapid growth spurt due to the success its new product line:

virtual chocolate. Devgood Chocolate is owned and operated by Grammy Devgood, who, of course, is our very own, Niki Devgood’s grandmother.

(6)

Course Objectives

Using XMLSpy, we will convert the Devgood Chocolate Company’s information processing systems into XML. Use the check list below to monitor the progress of the course as we complete topics. You will learn how to:

Topics 9

Navigate the three Parts of XMLSpy’s Main Window and their purpose

The Editing Views

New Document Creation

Storing New Templates in Program Files Folder Creating an Instance Document from a Schema Context Sensitive Entry Helper Windows

Validation Checking

Well-formedness Check Upon View Change Grid View Editing XML Documents

Generating an Instance Document from a Schema Differencing Tool

Generating a Schema from an Instance Document Generating a Schema: Text & Schema/WSDL View Editing in Schema/WSDL View

Generating Documentation from a Schema Generating Program Code from a Schema Generating Java Code from Schema

Import Database Data in an XML Document XML – Table Feature Revisited

XPath XPath Generator

XPath Evaluator

XSLT XSLT Engines

Debugging Debugger Windows

Debugger Tools

Other XSLT Commands & Toolbar Icons Project Window

Configuration Tips

(7)

Three Parts of XMLSpy’s Main Window

1 2 3

Project Window You can manage multiple files and URLs by grouping them into folders by common extension or any other order you choose.

1.

Info Window Displays meta information about the content located where you point your cursor.

2. Main Window or

Design Pane

This is:

• your work area

• where the document you are editing appears

The Views:

Text Grid Schema/WSDL Authentic Browser

Views appear once you begin to create a new document or when you open a

previously stored document or project file.

Depending on the type of document you are editing, determines the views available.

You can switch views any time you want by clicking on the appropriate tab.

Quick Tip CTRL-TAB To toggle between open documents Drag & Drop Open document names appear on tabs

along the bottom of the main window. To change the order in which they appear –

(8)

The Editing Views

Edit XML documents in multiple editing formats

You can switch among the various views to suit your convenience.

Views are XML language sensitive. What does that mean?

The type of XML document you have open dictates what views are available.

When a document is open, the editing format options appear horizontally along the bottom of the main window like this:

Editing Formats

Description

A text editing view with syntax-coloring.

For structured editing. The document is displayed as a structured grid, which can be manipulated graphically. This view also contains an embedded Database/Table view which shows repeating elements in a tabular format

For viewing and editing XML Schemas and WSDL documents For editing XML documents and databases based on StyleVision Power Stylesheets (essentially an XSLT stylesheet).

An integrated browser view that supports both CSS and XSL stylesheets.

NOTES:

(9)

The Technology

Before we get into it, let’s do a quick review of a few terms:

REVIEW QUESTIONS

1. What is XML?

A. eXtensible markup language – designed to display data and focuses on data transfer

B. eXtensible markup language – designed to display data and focuses on how the data looks.

C. eXtensible markup language – designed to describe data and focuses on what the data is.

D. extensible markup language – designed to deliver data and focuses on EDT

2. What is an XML Instance Document?

A. An XML document that contains markup and data.

B. Must always have an associated DTD or Schema.

C. It’s the document that describes the data.

D. It’s a document that displays the data.

NOTES:

(10)

Creating a New Document

From Main Menu: FILE |NEW

RESPONSE:

XMLSpy® 2006 comes loaded with the most commonly used industry standard XML document-types. Each document type includes a:

ƒ root element that serves as the document’s starting point.

ƒ template that references the corresponding DTD or schema

ƒ a validating parser to extract all relevant information about the content model.

ƒ constant feedback from the validating parser while you are editing your file.

NOTES:

(11)

Making & Storing Your Own Templates

If you don’t see the template you need, you can create your own and file it in the templates folder within your “Programs” file folder in your installation directory.

Storing Your Templates

GO TO: Program files folder, for example:

C:\ProgramFiles\Altova\XMLSpy2006\Template To Add the

File Name Extension

From Main Menu: TOOLS | OPTIONS| FILE TYPES

NOTES:

(12)

Creating an Instance Document from a Schema

Using VirtualRecipe.xsd

Let’s get back to our project. Back in the old country where the Devgood Chocolate Company was founded, the information processing systems were in a variety of formats. Our mission is to convert the Devgood Chocolate Company’s information systems into XML. We’re going to start with a virtual chocolate recipe. Niki, being a subject matter expert in intelligence and, of course, XML, created a schema for Grammy so we can use it to build our instance document.

But first, a review question:

3. What is a Schema Document?

A. A rough drawing of a new plan.

B. It’s another name for a DTD.

C. One instance of the data defined by the XML document.

D. It defines the content and structure of XML Instance Documents.

NOTES:

(13)

Creating an Instance Document from a Schema-(cont’d)

Two Options from the Main Menu, select –

OPTION 1: FILE |NEW

OPTION 2: DTD/SCHEMA|GENERATE SAMPLE XML FILE

OPTION 1

To Create A New XML Instance Document from a Schema

From the Main Menu: FILE |NEW RESPONSE:

Select: 1. XML Document 2. Click “OK”

(14)

RESPONSE: 1. Document prologue or XML declaration appears, auto generated by XMLSpy:

<?xml version="1.0" encoding="UTF-8"?>

2. Simultaneously, the option to assign a schema or DTD to your XML instance document also appears.

Creating XML Instance Based on an existing Schema

If you are creating a new XML document based on a schema, select the “Schema” radio button.

RESPONSE:

Select Schema to Associate to your XML document.

(VirtualRecipe.xsd)

Tools Defined In the “Choose a file:” box, by clicking on the down arrow, displays a list of documents used recently.

The “Browse” button allows you to search through you computer’s stored files.

The “Window” button lets you select a file from other windows open in XMLSpy like your Project files.

3. Now that we’ve selected VirtualRecipe.xsd, click “OK.”

(15)

Context Sensitive Entry Helper Windows

We now have an XML template that includes the content model from VirtualRecipe.xsd. Using our entry helpers we will:

ƒ build our instance document in the text view,

ƒ edit it in the text view,

ƒ and edit it in the grid view.

Elements Helper Window

Here’s our XML template that includes the content model from VirtualRecipe.xsd:

NOTES:

(16)

Context Sensitive Entry Helper Windows

- (cont’d)

Once XMLSpy® 2006 knows which schema or DTD your document is associated with it uses its integrated validating parser to extract all relevant information about the content model.

PLACE CURSOR Place cursor after “description” element.

Auto-filled Helper Windows

Notice how the Attributes, Elements and Entities helper windows fill with information.

Elements Helper Window:

ƒ Required elements are automatically highlighted by an exclamation mark.

ƒ Elements that are allowed within the current parent element, but not at the position of the current selection, are shown in gray.

EXAMPLE

Meta Information If you place your cursor on a specific line in the XML document, you get meta information about your content in the Information helper window.

EXAMPLE With your cursor placed after “description,” notice:

(17)

Context Sensitive Entry Helper Windows

- (cont’d) Add “number” attribute

to Recipe element

Remember in our content model, the element

“Recipe” had an attribute “number.”

How? After:

Insert cursor after end quotation mark after:

\VirtualRecipe.xsd

”|>

Notice how the “Attributes” entry helper displays: “= number”.

You can either:

1. double click on “= number” or

2. hit the space bar once and XMLSpy displays a pop up list of elements allowed at that point in the document.

3. Insert the number “1."

Another Editing Sample

Delete “candyName” 1. Insert the open bracked (<), a popup list of allowed elements appears. You can then select the appropriate element by clicking on it. All required attributes are entered as well.

2. When you insert the closing bracket (>), the end tag is automatically inserted.

3. The cursor is then positioned between the start and end tag of the element so that you can easily continue to add child elements or content.

(18)

Well-Formedness and Validation Checking

Now that we have an instance of our schema, is our document well-formed? Is it valid? It’s time for a few review questions.

4. What is well-formedness?

A. Documents that have the same parent elements B. Documents that have the same hierarchical structure.

C. Documents that are generated from Authentic and Stylevision D. Documents that conform to the rules and syntax established by

the W3C.

5. What is validation?

A. Validation confirms that your instance document meets expectations.

B. Validation is the process of comparison between a document and its standards.

C. A valid document is one that hasn’t yet met its expiration date.

D. Validation ensures there will be no error codes in your XSLT.

6. What is a valid XML instance document?

A. It is one that conforms to the instance B. It only relates to DTDs

C. It is one that always contains a namespace D. It is well-formed and conforms to the schema.

NOTES:

(19)

Well-Formedness and Validation Checking

Quick Tips

1. Should you still manage to create a sequence of elements that violates the content model specified by your schema or DTD or not ensure that your document is well-formed, the built-in incremental validating parser

automatically detects the violation and displays its error message directly in the entry helper window along the bottom of your main window.

2. There is an automatic well-formedness check when you change views. If the document isn’t well-formed, you won’t be able to change views!

NOTES:

(20)

Grid View Editing XML Documents

Adding Content in Grid

View

Grid View shows the hierarchical structure of XML documents through a set of nested containers that can be easily expanded and collapsed to get a clear picture of the document’s structure.

Contents and structure can both be easily manipulated.

The structure of the document in grid view provides the purest representation of its structure.

Benefits of Grid View Grid view allows you to…

ƒ view recurring elements in table form.

ƒ edit without touching the XML markup

ƒ view each child-type of the element displayed in a column

ƒ modify properties for entire columns or selections. (move column titles/change titles, etc.

ƒ insert row (add data-between other rows)

ƒ append row (add a new row at the bottom)

ƒ ascending sort

ƒ descending sort

ƒ insert and delete elements and attributes

ƒ modify names and namespaces

ƒ do drag and drop reorganizations With VirtualRecipe.xml Click on Grid:

(21)

Note: An element is denoted with the 〈〉 icon, an attribute with the = icon.

RESPONSE:

Three Ways to Add Another Ingredient:

First From the parent element “ingredients”

1. Click and highlight element “ingredients”

2. From Elements helper window , Click on “ADD CHILD”

(Add c… may only be visible) 3. “〈〉 ingredient” will appear 4. double click on ingredient

Second From ingredient (child element of ingredients)

1. In the grid, click to highlight element “ingredient”

2. Click “Append” (or “Insert” if you prefer), “〈〉 ingredient” will appear

Third With “ingredient” highlighted, go to:

(22)

Generating Instance From Schema

Creating the

Instance Document - Two Options from the Main Menu:

OPTION 2

Earlier, we promised you another option or another way to create an instance document from a schema. You can also generate a quick instance of your schema from the main menu.

Main Menu DTD/SCHEMA|GENERATE SAMPLE XML FILE RESPONSE

Click “OK” and poof! There you have the Instance document from the Schema!

Sample XML File Generated from VirtualRecipe.xsd

(23)

Differencing Tool

Comparing XML files (differencing)

From Main Menu:

Say for example, Grammy knows that she has two editions of each recipe. One copy has the secret ingredient in it and the other doesn’t. But she forgot which was which.

Tools|Compare Open File With …

Grammy can compare:

ƒ Any kind of text-based file

ƒ Directories

ƒ Documents

ƒ Folders Compare VirtualRecipe.xml

VirtualRecipe2.xml

NOTES:

(24)

Generate a Schema from an Instance Document

Using VirtualRecipe.xml

From Main Menu DTD/SCHEMA |GENERATE DTD/SCHEMA

In this example, the Schema generated is very similar to VirtualRecipe.xsd. There will be differences though.

Creating a Schema: Text & Schema/WSDL View

Example shows up to the CandyName element:

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema elementFormDefault="qualified"

attributeFormDefault="unqualified">

<xs:element name="Recipe">

<xs:complexType>

<xs:sequence>

<xs:element name="candyName" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

NOTES:

(25)

Editing a Schema in Grid View

Editing a Schema in Text and Grid View is as easy as editing an XML instance document in text and grid view. The Entry Helpers function the same way. For additional practice, try to recreate segments of VirtualRecipe.xsd in the text view then in grid view.

Using the auto generated VirtualRecipe.xsd, try some additional practice with Grid View:

Adding Elements in Grid View

1. Highlight the xs:element for candyName.

2. From the Elements Helper box

3. Click on Append, Double click on 〈〉xs:element RESULT 4. Another 〈〉xs:element is inserted:

5. Go to Attributes Helper Box, click on ”Add c…” (for Child) 6. double click on “=name” (to insert it)

(26)

RESULT 7. click in field next to “=name”

8. insert element name “description”

9. With “=name description “ highlighted, for example:

10. Go to the Attributes Entry Helper box 11. Click on the Append tab,

12. Double click on “=type”

13. indicate type as “xs:string”

RESULT Your schema in grid view now looks like this:

What now?

Continue in Schema/WSDL View

We’ve looked at creating or editing a schema in:

ƒ text view

ƒ grid view

Let’s switch to the Schema/WSDL view. We call it Visual XSD: it’s the first course in our schema development accelerated series.

(27)

Editing in Schema/WSDL View

Switch to Visual Schema View – Add elements in the visual view.

ƒ The schema editor in XMLSpy® 2006 lets you manage the relationships and definitions in your schema visually.

ƒ As you develop your schema using the graphical Schema/WSDL view, the corresponding XML code is generated and can be viewed in text view.

So, while you design your schema visually, XMLSpy is generating the hand coding for you.

Using VirtualRecipe.xsd

Here’s our VirtualRecipe.xsd in the Schema/WSDL view. Let’s walk through how it’s done.

Go Back to Schema Under Construction Untitled*.xsd Add Child Elements to Recipe

First, add a sequence compositor to Recipe. Then add:

ELEMENT

NAME

COMPOSITOR CHILD

ELEMENT

NAME

DATA TYPE CARDINALITY

candyName N/A N/A String

description N/A N/A String

ingredients Sequence ingredient String 1..∞

instructions Sequence step String Unbounded Change local

elements to global

Go back change these local elements to global:

ƒ candyName

(28)

Add Attributes

ELEMENT NAME ATTRIBUTE NAME ATTRIBUTE DATA TYPE

Recipe number xs:positiveInteger candyName productLine Xs:string

Add Facets – Enumerated list to productLine

1. Highlight attribute:

productLine

2. Go to Facets entry helper window

3. Click on “Enum…” tab 4. Click on Append icon 5. Add: Solid, Truffles,

Carmels & Virtual

Facets- Patterns

You can write regular expressions to restrict what is allowed in a particular value space. In XMLSpy, you will use the “Patterns”

feature. We aren’t going to use regular expressions in this example but should you need this feature we wanted you to know it’s there!

1. With the Patterns tab highlighted, click either Append or Insert.

A list of metacharacters and what they represent appear in the drop down list to help you write your regular expression.

Result:

(29)

Component Navigator in Schema/WSDL Design View

Just above that Facets entry helper window is the Component Navigator.

Two purposes:

1. To organize global components in a tree view by

component type and namespace (see screenshots below).

This provides organized overviews of all global components.

2. To enable you to navigate to and display the Content Model View of a global component —if the component has a content model.

3. If a component does not have a content model, component is highlighted in the Schemas Overview. Global components that are included or imported from other schemas are also

displayed in the Component Navigator.

(30)

Generate Documentation from a Schema

SCHEMA DESIGN

|GENERATE DOCUMENTATION

Everyone knows how important it is to document your code when you design. XMLSpy makes it easy for you. Let me show you how.

Steps 1. From Main Menu, click on SCHEMA DESIGN |GENERATE DOCUMENTATION

Two Choices of Output

Benefits:

ƒ Two choices of output: HTML or Microsoft Word

ƒ Options of what you would like to include

ƒ How much detail do you want to see?

Steps (cont’d) 2. Choose your preferences

3. Name the output document and save it.

(31)

Generating Program Code from a Schema

DTD/SCHEMA |

|GENERATE PROGRAM CODE

So, we know that XML is not a programming language. However, XML documents are often processed by a computer program.

How do we get the computer program to interpret the XML?

Well, you could hand code it but we’ve got a faster option for you.

To create the necessary infrastructure code –

or in other words to create the required object model –

you can generate program code from a schema with XMLSpy.

(32)

Generate Java code from Schema

Step Process Explanation

1. Have schema file open: Code can only be generated from a valid schema file.

2. From main menu DTD/SCHEMA|

GENERATE PROGRAM CODE 3. Choose Template Dialog box appears…

4. Select – “Java” tab* Use this template:

c:\program files\altova\xmlspy2006\spl\java.spl

6. Select Target Directory Dialog box (“Browse For Folder”) appears asking you to:

“Please Select target directory.”

7. Open Corresponding Output directory

1. Spy asks you to open the directory you previously created. (For this demo, we will say NO.)

2. The java class files and line of code will be generated.

(33)

Import Database Data (XML Document)

Devgood

Chocolate Product Line

The Devgood Chocolate Company’s product line is stored in a database. Not to worry though, XMLSpy can import database data from the most commonly used databases.

For example, you can import from:

• Access,

• MS SQL Server

• Oracle

• MySQL

• Sybase

• IBM DB2

Convert DevgoodChocolatesProducts.mdb

Database Import We’re going to import database data into an XML file and generate an XML Schema file to correspond to the database structure.

From Main Menu CONVERT | IMPORT DATABASE RESPONSE

(34)

Importing From

Select Database File Name

(35)

Click on Import: Voila!

(36)

XML |TABLE Feature Revisited Table features of imported DevgoodChocolatesProducts

With the Devgood Choocolate Company’s product list now in XML, let’s revisit grid view and how its table feature displays the data.

From Main Menu XML |TABLE

Benefits of Table View:

ƒ allows you to view recurring elements in table form.

ƒ Allows you to edit without touching the XML markup

ƒ You can then modify properties for entire columns or selections. (move column titles/move

columns//change titles, etc.)

ƒ Insert Row (Add data)

ƒ Append Row

ƒ Ascending Sort

ƒ Descending Sort

(37)

XPath, XSLT Debugging and Transformation

XPath

We know that, on its own, an XML Instance Document doesn’t do anything. We need to transform the information it holds into something else. To transform it, we need to be able to locate the information or nodes (as they are called) within the XML document. We do that with XPath.

REVIEW QUESTION

7. What is XPath?

A. A new train line in Boston funded by money left over from the big dig.

B. XPath is a language that sends messages via nodes in Schema documents.

C.

XPath is a language written in expressions designed to locate parts of XML documents.

D. XPath is another name for XSLT.

Notes:

(38)

XPath Generator

How do we write XPath expressions?

EDIT | COPYXPATH

Well, learning XPath’s syntax and structure is an entirely different class which we offer in the XSLT accelerated series. However, XMLSpy has a tool that will help.

Using VirtualRecipe.xml in Grid View

1. Highlight the instructions node 2. From main menu, Edit |Copy XPath

ƒ XMLSpy creates an XPath expression and copies it to the clipboard. (It doesn’t create predicates.)

/Recipe/instructions

ƒ This enables you to test your XPath expression Note You may be thinking, “why can’t you build an XPath

expression from the text view?”

Keep in mind, you aren’t evaluating content. You are evaluating the structure. Therefore, the purest structure of the instance document is in the grid view.

XPath Evaluator

XML |EVALUATE XPATH Now what? We can test the XPath expression that we just generated by using the Evaluate XPath feature and see what it returns.

Test Expressions:

/Recipe/instructions/step And /Recipe/instructions/step[10]

Having copied the XPath expression in the grid view open the XPath evaluator:

From Main Menu XML |EVALUATE XPATH Three sections of

XPath Evaluator

The XPath Evaluator opens and you can see it’s got three distinct sections:

ƒ input pane

ƒ options area

ƒ results pane

(39)

XPath Evaluator (cont’d)

Input Pane The Input Pane is where you paste the XPath expression that you copy.

Options Pane Your choices are…

Meaning of the Choices

Allow Complete XPath Full XPath 1.0 grammar

XML Schema Selector XML Schema Selector grammar XML Schema Field XML Schema Field grammar From Document Root Absolute Path

From Selected Element

Relative Path

Evaluate when typing Have the evaluator respond as you type – real time

Evaluate on button click

Results of the evaluator appear when you click on the Evaluate button.

XPath 1.0 XPath 2.0

XPath Version

Results Pane The result is a list of items with their corresponding

values. Selecting an item in the list causes that item to be highlighted in the Main Window. Let’s test our expression.

Test Expression (cont’d)

Place cursor inside input pane and paste the expression from the clip board into the input pane.

/Recipe/instructions/step

Take a look at what’s returned in the result pane:

(40)

RESULT

Add Predicate Add a predicate after” /step”: [11]

Look at what’s returned after adding the predicate.

XPath Generator Doesn’t create predicates (segment enclosed in brackets – topic covered in Navigating XPath)

(41)

XSLT

We said just a few minutes ago that by locating nodes, XPath enables other XML technologies to transform data into something else. For example in an XSLT stylesheet. It’s review time.

REVIEW QUESTION

8. What is XSLT?

A. It means the same thing as XSL

B. eXtensible Stylesheet Language Transformation – a language for transforming XML

C. The same as XHTML

D. A formatting objects language

Converting

VirtualRecipe.xml into HTML with XSLT

We don’t get into the syntax and structure of the XSLT language in this class, which is another class in itself also.

However, Niki created a simple stylesheet that we can use to transform our virtual recipe into HTML that will be used on Grammy Devgood’s new web site. She likes to feature a recipe every now and then.

Stylevision Niki certainly could have hand coded this stylesheet but to save time, she created it in our product Stylevision and saved the XSLT file that was auto generated.

Notes:

(42)

XSLT Engines

Two Built-in Engines To run a transformation, you need a transformation engine.

XMLSpy has two built in engines: 1.0 and 2.0. XMLSpy selects the appropriate engine based on the version attribute in the xsl:stylesheet or xsl:transform element. You use 1.0 with 1.0 XSLT Stylesheets and 2.0 with 2.0 XSLT Stylesheets.

To select an External XSL

transformation program:

For example say you were going to use something like Saxon 8.3:

java –jar C:\saxon8.3\saxon8.jar –o %2 %1 %3

Run Transformation XSL/XQUERY |XSL TRANSFORMATION

With VirtualRecipe.xml open, run the transformation. This menu choice will not permanently assign the XSLT document to your XML document.

If you wanted a permanent assignment, you would either select:

ƒ XSL/XQUERY |ASSIGN XSL

ƒ XSL/XQUERY |ASSIGN SAMPLE XML FILE

(43)

RESULT Within seconds you have your HTML output. Something’s gone wrong though. Compared to our XML instance document, our list of ingredients is missing. Looks like debugging is in order!

(44)

Debugging

Using

VirtualRecipe.xml and VirtualRecipe.xslt

Debugger works in text and grid views

XSLT/XQUERY |START DEBUGGER/GO

With VirtualRecipe.xml in the main window, start the debugger. Again, this is not a permanent association.

Simultaneous Views The XSLT/XQuery Debugger interface presents simultaneous view of:

ƒ Source XML document

ƒ XSLT/XQuery document

ƒ Result document Interface Windows –

Debugging Info

While a debugging session is open,

information windows in the interface provide information about various aspects of the transformation being executed.

ƒ Context

ƒ Variables,

ƒ XPath Watch,

ƒ Call Stack

ƒ Templates

ƒ Info

ƒ Messages

(45)

Debugger Windows

The Context Window displays the current processing context:

ƒ A sequence of nodes

ƒ A single node

ƒ Or an atomic value (string perhaps)

Depending on the kind of a context item, its value or attribute/s is/are displayed.

Example:

1. if the context item is an element, the element's attributes are displayed.

2. If the context item is an attribute or text node, the node's value is displayed.

Note: Clicking an entry in the Context Window, displays that item in the XML document.

If the XML document is not currently displayed in the interface, a window for the XML document will be opened.

It displays the variables and parameters that are used in the XSLT/XQuery document

when they are in scope, and their values.

I haven’t used any in this XSLT. A little more advanced than my document needed.

Enter:

/Recipe/instructions/step[11]

It enables you to enter XPath expressions

that you want to evaluate in one or more contexts.

As you step through the XSLT document,

the XPath expression is evaluated in the current context and the result is displayed in the Value column.

To enter an XPath expression, double-click in the text field under the Name column and enter the XPath expression.

(46)

Displays a list of processed XSLT templates and instructions.

Clicking an entry in this window, causes the selected XSLT template/instruction to be displayed in the XSLT document window. In other words, by highlighting the template in the Call Stack results list, highlights it in the XSLT document.

Displays error messages – if you had any

Displays the list of templates in your XSLT document.

(Not available in XQuery debuggings session.)

It provides meta information about the current debugging session. It includes:

ƒ what debugger is being used,

ƒ the names of the source and output documents,

ƒ and the status of the debugger.

(47)

Debugger Tools

Insert Breakpoint Since we seem to know where our problem is occurring, we can insert break points in our XSLT document to interrupt the processing close to that point so that we can evaluate what the problem is.

Benefit This speeds up debugging sessions since you do not have to step through each statement in the XSLT or XQuery document manually. The debugger only stops at those designated points.

Describe Debugger Tools Insert/Remove Breakpoint

(F9)

Inserts or removes a breakpoint at the current cursor position. Inline breakpoints can be defined for nodes in both the XSLT/XQuery and XML documents, and

determine where the processing should pause. A dashed red line appears above the node when you set a

breakpoint. Breakpoints cannot be defined on closing nodes, and breakpoints on attributes in XSLT documents will be ignored. This command is also available by right- clicking at the breakpoint location.

Insert the Breakpoint Note:

In VirtualRecipe.xslt on line 41, insert the breakpoint. The example bug is a misspelling of ingredients (ingrediants).

(48)

XSLT Breakpoints Dialog This command pops up the XSLT/XQuery Breakpoints dialog, which displays a list of all currently defined

breakpoints (including disabled breakpoints) in all files in the current debugging session.

Check Boxes Enables (9) breakpoint Disables ( ) breakpoint

Removes the highlighted breakpoint Removes ALL breakpoints

Highlighted, it takes you directly to that breakpoint in the file.

(49)

Options for Proceeding Through your XSLT Document

XMLSpy offers you several ways in which you can proceed or progress through your debugging session.

You can:

ƒ Start Debugger/Go

ƒ Step Into

ƒ Step Over

ƒ Step Out Start

Debugger/Go

Starts or continues processing the XSLT/XQuery document till the end.

(unless you put in breakpoints)

Step Into The Step Into command proceeds in single steps through all nodes and XPath expressions.

Step Over Steps over the current node to the next node at the same level, or to the next node at the next higher level from that of the current node.

Step Out Steps out of the current node to the next sibling of the parent node, or to the next node at the next higher level from that of the parent node.

Each one of these options can also be used to restart the debugger after it has been stopped.

Finish Running Debugging Session and Correct Bug

Fix typo and “Step Over” to continue.

Stop debugger ƒ pauses the debugger. You can edit any of your documents while the degugger is paused.

ƒ All editing features that are available in your

XMLSpy 2006 environment are also available while editing a file during a debugging session.

End debugging session

concludes the debugging session.

When you “stop” a debugging session, it closes the

XSLT/XQuery Debugger interface and returns you to your previous XMLSpy 2006 environment.

(50)

Other XSLT Commands & Toolbar Icons

Show current execution

node

Displays/selects the current execution node in the

XSLT/XQuery document and the corresponding context node in the XML document. This is useful when you have clicked in other tabs which show or mark specific code in the XSLT stylesheet or XML file, and you want to return to where you were before you did this.

Restart Debugger Clears the output window and restarts the debugging session with the currently selected files.

The View Icons Now, having completed the debugging session, show the Output document by clicking on the “vew” icons in reverse order:

View XML, XSL, Output The current view

View XSLT and Output XSLT and Output

View the Active Document Only

Here’s our end product, the HTML Output - VirtualRecipe.html Grammy Devgood’s html recipe.

(51)

Project Window

Project Now that we have created all of these files, let me show you how you can store them in XMLSpy.

(52)

Function of the Project Window

You can:

• organize files and groups of files in a tree-like structure

• group folders by common extension or any way you choose

• add file types you don’t see here that you commonly use,

• Execute batch operations across files Project folders are:

• “semantic” folders that represent a logical grouping of files.

They do not need to correspond to any hierarchical organization of files on your hard disk

• can correspond to physical directories on your file system Managed similarly to a “short cut.”

PROJECT |NEW PROJECT

Open a new project and begin saving the files you created.

• opens a new project.

• The new project will be named “New Project.’

• When you go to “Save Project,” you will be prompted to name the project.

When to create your Project

You can create and save in your project file whenever you choose.

Normally, you would add files to your project as your project progresses. In this situation, we use a previously created project file and are drawing from it for this course.

(53)

|Reload Project If you are working in a multi-user environment, it can sometimes become necessary to reload the project from disk, because other users might have made changes or updates to files within it.

|Close Project Closes the project.

|Save Project Saves the project.

Add Files to Project Enables you to add files to the current open project and distributes them among the respective folders based on the file type

extensions defined in the project properties dialog box. You can save a single file or a group of files (Ctrl+ click).

(54)

Add URL to Project Adds a URL to the current project. URLs in a project cause the target object of the URL to be included in the project. Whenever a batch operation is performed on a URL or on a folder that contains a URL object, XMLSpy retrieves the document from the URL and performs the requested operation.

Add Active File to Project

Add the open file to the open project.

Add Active and Related Files to Project

Adds any related files to the project.

For example, say we are adding the VirtualRecipe.xml to the project, we know that it is related to the VirtualRecipe.xsd.

Therefore, XMLSpy will also add the related schema.

(55)

Add Project Folder to Project

Note: This command retrieves the same properties box as “Project Properties.”

Use this command to add a new folder to the current project or a sub-folder to a project folder. For example, Niki added database files to this project and created a folder for Database Files. She did this using the “Add Project Folder to Project” command and added

“Database Files” with the.mdb File Extension

You can also access this command from the context-menu when you right-click on a folder in the project window.

(56)

Add External folder to Project

Filter

Allows you to add any other folder from files or folders on your computer to your project.

This is how I added the link to the Java generated files you see in my project.

You can also “filter” the files included by going to the Properties box and entering the file extensions of the file types you want to see.

(57)

Add External Web

Folder to Project You can also add web folders to your project. These can be filtered as well. We haven’t done that here in our example.

(58)

Batch Manipulation/

Project Properties

You can assign:

ƒ XSL transformation to project folders

ƒ DTDs/Schemas to project folders

(59)

Last note on “project.”

PROJECT |OPEN PROJECT VERSUS FILE |OPEN

Be sure you use the Project |Open menu selection to open your project. If you use File| Open, you will be opening the actual XML file of your project!

(60)

XMLSpy’s Additional Features

Graphical editing view

of XML documents in Authentic View

XMLSpy also provides a graphical editing view of XML documents in Authentic View which enabling users to enter data into an XML document as they would into a wordprocessor-type application.

Authentic View is particularly useful in situations where:

ƒ people not familiar to XML are called upon to enter data into an XML document, or where

ƒ several users input data into, or view, a single document located on a server or shared resource.

WSDL and SOAP The Schema/WSDL View enables you to create and edit WSDL documents in an easy-to-use graphical interface. You can also create and edit SOAP requests within the IDE and debug SOAP requests.

Visual Studio .NET integration

XMLSpy can be integrated in your Visual Studio .NET environment.

You can access XMLSpy editing views and XML development tools from within the Visual Studio .NET. To do this, you will need to install either the Enterprise or Professional Edition of XMLSpy, Microsoft® Visual Studio® .NET 2002 or 2003 and XMLSpy’s integration module.

Eclipse Development Platform

Altova supports Eclipse integration in its Home Edition as well as with the Enterprise and Professional Editions.

XQuery XMLSpy® 2006 includes schema-aware support for XQuery 1.0, including creating, editing, debugging, and executing XQuery files.

References

Related documents

Within the last few years, the evidence base for psychological interventions in the treatment of PTSD in asylum seeker and refugee populations has grown, with implications for

Select the Identity Center's entry in the console tree and choose New/Folder… from the context menu to create the folder.. Create a job by selecting the folder's entry and

Functionality for new social media schema and processes individual data beginning at the real world schema project or premium database in a new files.. Rebuilding validation for

In the next task you'll synchronize files in a Windows folder by creating a file sharing workspace... Start sharing files in a

If you want to delete a file from an included folder, delete it from the original location, not the library.. Deleting it from the library will also delete it from the

• Upload the annotated pdf document from Adobe Reader to Windows Skydrive • Share a folder in Windows Skydrive.. • Create a new folder in Dropbox • Upload images

Creating a ShareDirect folder from the ShareDirect Console 10 Creating a ShareDirect Folder from Windows Explorer 12 Creating a ShareDirect Folder from the ShareDirect Toolbar

Kiss2 expression was increased in the male F2 generation EE2 High (p &lt; 0.05) and ATZ Low (p &lt; 0.05) treatment lineages compared to the control lineage, while there were