INTRO TO XMLSPY (IXS) Student Notebook Intro to XMLSpy Page - 1 Revised: 11/8/2005 - 3:25:38 PM 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 Intro to XMLSpy Page - 2 Revised: 11/8/2005 - 3:25:38 PM 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 This notebook was written to accompany the online, instructor-lead, 2-hour course entitled “Intro to XMLSpy.” It was not intended as a stand-alone tutorial. Intro to XMLSpy Page - 3 Revised: 11/8/2005 - 3:25:38 PM Example Files Example files included in this package: Intro to XMLSpy Page - 4 VirtualRecipe.xml VirtualRecipe.xsd VirtualRecipe.xslt VirtualRecipe.html DevgoodChocolatesProducts.mdb Revised: 11/8/2005 - 3:25:38 PM 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. Intro to XMLSpy Page - 5 Revised: 11/8/2005 - 3:25:38 PM 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 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 Intro to XMLSpy Page - 6 9 Revised: 11/8/2005 - 3:25:38 PM Three Parts of XMLSpy’s Main Window 1 1. 2 3 You can manage multiple files and URLs by grouping them into folders by common extension or any other order you choose. Info Window Displays meta information about the content located where you point your cursor. 2. Main Window or This is: Design Pane • your work area • where the document you are editing appears The Views: Views appear once you begin to create a Text new document or when you open a Grid previously stored document or project file. Schema/WSDL Authentic Depending on the type of document you Browser 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 – drag & drop. These are context sensitive – they change 3. Entry Helpers based on the type of document that is active in the Main Window. Intro to XMLSpy Project Window Page - 7 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy Page - 8 Revised: 11/8/2005 - 3:25:38 PM The Technology Before we get into it, let’s do a quick review of a few terms: REVIEW 1. What is XML? QUESTIONS 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. B. C. D. An XML document that contains markup and data. Must always have an associated DTD or Schema. It’s the document that describes the data. It’s a document that displays the data. NOTES: Intro to XMLSpy Page - 9 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy Page - 10 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy Page - 11 Revised: 11/8/2005 - 3:25:38 PM 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. B. C. D. A rough drawing of a new plan. It’s another name for a DTD. One instance of the data defined by the XML document. It defines the content and structure of XML Instance Documents. NOTES: Intro to XMLSpy Page - 12 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy 1. XML Document 2. Click “OK” Page - 13 Revised: 11/8/2005 - 3:25:38 PM 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 If you are creating a new XML document based on a schema, select Instance Based on an the “Schema” radio button. existing Schema RESPONSE: Select Schema to Associate to your XML document. (VirtualRecipe.xsd) Tools Defined Intro to XMLSpy 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.” Page - 14 Revised: 11/8/2005 - 3:25:38 PM 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: Elements Helper Window build our instance document in the text view, edit it in the text view, and edit it in the grid view. Here’s our XML template that includes the content model from VirtualRecipe.xsd: NOTES: Intro to XMLSpy Page - 15 Revised: 11/8/2005 - 3:25:38 PM 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 Notice how the Attributes, Elements and Entities helper windows fill Helper Windows 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: Intro to XMLSpy Page - 16 Revised: 11/8/2005 - 3:25:38 PM Context Sensitive Entry Helper Windows- (cont’d) Add “number” attribute Remember in our content model, the element to Recipe 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” Intro to XMLSpy 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. Page - 17 Revised: 11/8/2005 - 3:25:38 PM 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. B. C. D. Documents that have the same parent elements Documents that have the same hierarchical structure. Documents that are generated from Authentic and Stylevision 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. B. C. D. It is one that conforms to the instance It only relates to DTDs It is one that always contains a namespace It is well-formed and conforms to the schema. NOTES: Intro to XMLSpy Page - 18 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy Page - 19 Revised: 11/8/2005 - 3:25:38 PM Grid View Editing XML Documents Adding Content in Grid Grid View shows the hierarchical structure of XML documents View 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: Intro to XMLSpy Page - 20 Revised: 11/8/2005 - 3:25:38 PM 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. 2. In the grid, click to highlight element “ingredient” Click “Append” (or “Insert” if you prefer), “〈〉 ingredient” will appear Third With “ingredient” highlighted, go to: Menu: XML |APPEND |ELEMENT Changing Element names Change the element name “ingredient” to “contents.” & Their Order Intro to XMLSpy Page - 21 Revised: 11/8/2005 - 3:25:38 PM Generating Instance From Schema Earlier, we promised you another option or another way to create an Creating the Instance Document - instance document from a schema. You can also generate a quick instance of your schema from the main menu. Two Options from the Main Menu: OPTION 2 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 Intro to XMLSpy Page - 22 Revised: 11/8/2005 - 3:25:38 PM Differencing Tool Comparing XML files (differencing) 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. From Main Menu: Tools|Compare Open File With … Grammy can compare: Any kind of text-based file Directories Documents Folders Compare VirtualRecipe.xml VirtualRecipe2.xml NOTES: Intro to XMLSpy Page - 23 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy Page - 24 Revised: 11/8/2005 - 3:25:38 PM 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) Intro to XMLSpy Page - 25 Revised: 11/8/2005 - 3:25:38 PM 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? We’ve looked at creating or editing a schema in: Continue in Schema/WSDL View 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. Intro to XMLSpy Page - 26 Revised: 11/8/2005 - 3:25:38 PM 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 Here’s our VirtualRecipe.xsd in the Schema/WSDL view. Let’s walk VirtualRecipe.xsd through how it’s done. Go Back to Schema Under Construction Untitled*.xsd Add Child Elements First, add a sequence compositor to Recipe. Then add: to Recipe ELEMENT NAME COMPOSITOR CHILD ELEMENT NAME DATA TYPE candyName N/A N/A String description N/A N/A String ingredients Sequence ingredient String instructions Sequence step String Change local Go back change these local elements to global: elements to global candyName description ingredients and instructions Intro to XMLSpy Page - 27 CARDINALITY 1..∞ Unbounded Revised: 11/8/2005 - 3:25:38 PM Add Attributes ELEMENT NAME ATTRIBUTE NAME ATTRIBUTE DATA TYPE Recipe candyName number productLine xs:positiveInteger Xs:string Add Facets – 1. Highlight attribute: productLine Enumerated list to 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- You can write regular expressions to restrict what is allowed in a Patterns 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: Intro to XMLSpy Page - 28 Revised: 11/8/2005 - 3:25:38 PM Component Just above that Facets entry helper window is the Component Navigator in Navigator. Schema/WSDL Design View Two purposes: 1. 2. 3. Intro to XMLSpy To organize global components in a tree view by component type and namespace (see screenshots below). This provides organized overviews of all global components. To enable you to navigate to and display the Content Model View of a global component —if the component has a content model. 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. Page - 29 Revised: 11/8/2005 - 3:25:38 PM Generate Documentation from a Schema SCHEMA DESIGN |GENERATE DOCUMENTATION Steps Everyone knows how important it is to document your code when you design. XMLSpy makes it easy for you. Let me show you how. 1. From Main Menu, click on SCHEMA DESIGN |GENERATE DOCUMENTATION Two Choices of Benefits: Output 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) Intro to XMLSpy 2. Choose your preferences 3. Name the output document and save it. Page - 30 Revised: 11/8/2005 - 3:25:38 PM 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. Intro to XMLSpy Page - 31 Revised: 11/8/2005 - 3:25:38 PM Generate Java code from Schema Step Process 1. Have schema file open: 2. From main menu Explanation Code can only be generated from a valid schema file. 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 Intro to XMLSpy 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. Page - 32 Revised: 11/8/2005 - 3:25:38 PM 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 Intro to XMLSpy Page - 33 Revised: 11/8/2005 - 3:25:38 PM Importing From Select Database File Name Intro to XMLSpy Page - 34 Revised: 11/8/2005 - 3:25:38 PM Click on Import: Voila! Intro to XMLSpy Page - 35 Revised: 11/8/2005 - 3:25:38 PM XML |TABLE Feature Revisited Table features of imported With the Devgood Choocolate Company’s product list DevgoodChocolatesProducts 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: Intro to XMLSpy 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 Page - 36 Revised: 11/8/2005 - 3:25:38 PM 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 7. What is XPath? QUESTION 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: Intro to XMLSpy Page - 37 Revised: 11/8/2005 - 3:25:38 PM XPath Generator How do we write XPath Well, learning XPath’s syntax and structure is an entirely expressions? different class which we offer in the XSLT accelerated series. However, XMLSpy has a tool that will help. EDIT | COPYXPATH Using VirtualRecipe.xml in 1. Highlight the instructions node Grid View 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. Having copied the XPath expression in the grid view open Test Expressions: /Recipe/instructions/step the XPath evaluator: And /Recipe/instructions/step[10] From Main Menu XML |EVALUATE XPATH Three sections of The XPath Evaluator opens and you can see it’s got three XPath Evaluator distinct sections: Intro to XMLSpy input pane options area results pane Page - 38 Revised: 11/8/2005 - 3:25:38 PM 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 Evaluate when typing Relative Path Evaluate on button click Have the evaluator respond as you type – real time Results of the evaluator appear when you click on the Evaluate button. XPath 1.0 XPath Version XPath 2.0 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 Place cursor inside input pane and paste the expression (cont’d) from the clip board into the input pane. /Recipe/instructions/step Take a look at what’s returned in the result pane: Intro to XMLSpy Page - 39 Revised: 11/8/2005 - 3:25:38 PM RESULT Add Predicate Add a predicate after” /step”: [11] Look at what’s returned after adding the predicate. XPath Generator Intro to XMLSpy Doesn’t create predicates (segment enclosed in brackets – topic covered in Navigating XPath) Page - 40 Revised: 11/8/2005 - 3:25:38 PM 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 8. What is XSLT? QUESTION 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: Intro to XMLSpy Page - 41 Revised: 11/8/2005 - 3:25:38 PM 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 With VirtualRecipe.xml open, run the transformation. This menu choice will not permanently assign the XSLT document to XSL/XQUERY |XSL your XML document. TRANSFORMATION If you wanted a permanent assignment, you would either select: Intro to XMLSpy XSL/XQUERY |ASSIGN XSL XSL/XQUERY |ASSIGN SAMPLE XML FILE Page - 42 Revised: 11/8/2005 - 3:25:38 PM 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! Intro to XMLSpy Page - 43 Revised: 11/8/2005 - 3:25:38 PM 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: 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. Intro to XMLSpy Source XML document XSLT/XQuery document Result document Context Variables, XPath Watch, Call Stack Templates Info Messages Page - 44 Revised: 11/8/2005 - 3:25:38 PM 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. It enables you to enter XPath expressions that you want to evaluate in one or more contexts. Enter: As you step through the XSLT document, /Recipe/instructions/step[11] 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. Intro to XMLSpy Page - 45 Revised: 11/8/2005 - 3:25:38 PM 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: Intro to XMLSpy what debugger is being used, the names of the source and output documents, and the status of the debugger. Page - 46 Revised: 11/8/2005 - 3:25:38 PM 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 Inserts or removes a breakpoint at the current cursor (F9) 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 rightclicking at the breakpoint location. Insert the Breakpoint In VirtualRecipe.xslt on line 41, insert the breakpoint. The Note: example bug is a misspelling of ingredients (ingrediants). Intro to XMLSpy Page - 47 Revised: 11/8/2005 - 3:25:38 PM 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. Intro to XMLSpy Page - 48 Revised: 11/8/2005 - 3:25:38 PM 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 Starts or continues processing the Start Debugger/Go 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. Finish Running Debugging Session and Correct Bug Stop debugger 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. Fix typo and “Step Over” to continue. 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. Intro to XMLSpy Page - 49 Revised: 11/8/2005 - 3:25:38 PM Other XSLT Commands & Toolbar Icons Show current execution Displays/selects the current execution node in the node 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 Here’s our end product, the HTML Output - VirtualRecipe.html Only Grammy Devgood’s html recipe. Intro to XMLSpy Page - 50 Revised: 11/8/2005 - 3:25:38 PM Project Window Project Now that we have created all of these files, let me show you how you can store them in XMLSpy. Intro to XMLSpy Page - 51 Revised: 11/8/2005 - 3:25:38 PM Function of the Project You can: Window • 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. • • • When to create your Project Intro to XMLSpy 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. 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. Page - 52 Revised: 11/8/2005 - 3:25:38 PM |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 Intro to XMLSpy 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). Page - 53 Revised: 11/8/2005 - 3:25:38 PM 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. Intro to XMLSpy 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. Page - 54 Revised: 11/8/2005 - 3:25:38 PM 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. Intro to XMLSpy Page - 55 Revised: 11/8/2005 - 3:25:38 PM Add External folder to Project 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. Filter 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. Intro to XMLSpy Page - 56 Revised: 11/8/2005 - 3:25:38 PM Add External Web Folder to Project Intro to XMLSpy You can also add web folders to your project. These can be filtered as well. We haven’t done that here in our example. Page - 57 Revised: 11/8/2005 - 3:25:38 PM Batch Manipulation/ Project Properties You can assign: Intro to XMLSpy XSL transformation to project folders DTDs/Schemas to project folders Page - 58 Revised: 11/8/2005 - 3:25:38 PM Last note on “project.” PROJECT |OPEN PROJECT Be sure you use the Project |Open menu selection to open VERSUS your project. If you use File| Open, you will be opening the FILE |OPEN actual XML file of your project! Intro to XMLSpy Page - 59 Revised: 11/8/2005 - 3:25:38 PM XMLSpy’s Additional Features Graphical editing view XMLSpy also provides a graphical editing view of XML documents of XML documents in in Authentic View which enabling users to enter data into an XML Authentic View 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 XMLSpy can be integrated in your Visual Studio .NET environment. integration 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 Altova supports Eclipse integration in its Home Edition as well as Platform 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. Intro to XMLSpy Page - 60 Revised: 11/8/2005 - 3:25:38 PM
© Copyright 2026 Paperzz