the use of xmlspy - hong kong polytechnic …click [schema design] Ł[generate documentation… ]...
TRANSCRIPT
The Use of XMLSpy
COMP5323Web Databases & Applications
User Interface
Info Window, which displays meta
information about the document item being
currently edited.
Main Window, where the document you edit appears.
Entry Helper Windows, which vary
according to the type of document
being viewed and the view
selected in the Main Window.
Output Windows, below the Main Window show the results of Validation, Find in Files, and
XPath evalustions.
Project Window, which allows you to
organize and edit files and groups of files
into projects.
XML Schemas: BasicsCreating a new XML Schema File
To run the application, select [Start] è [Programs] è [Altova
XMLSpy 2008 Enterprise Edition] è[Altova XMLSpy]
XML Schemas: BasicsCreating a new XML Schema File (1)
1. Choose [File] è [New]
1
2. Select [xsd W3C XML Schema]
2
XML Schemas: BasicsCreating a new XML Schema File (2)
21
1. Enter “Company”2. Enter “Root Element”
l Save it first
XML Schemas: BasicsCreating a new XML Schema File (3)
1. Select [File] è [Save]
2. Enter “AddressFirst” in [File name] box.
3. Press [Save] button
XML Schemas: BasicsDefine Namespaces
1. Select [Schema design] è [Schema Settings… ]
2. In [Target namespace] box, enter http://my.company.com/namespace
3. Press [OK]
1
2
3
XML Schemas: BasicsDefine Content Model
Click [Display Diagram] icon of the [Company]
element
XML Schemas: BasicsDefine Content Model (2)
Sequence compositor is generated
Right click on [Company], select [Add child] è [Sequence]
Enter “Address”
Right click the [Sequence] compositor and select [Add child] è [Element]
XML Schemas: BasicsDefine Content Model (3)
XML Schemas: BasicsDefine Content Model (4)
Try to add [Person] yourself.
XML Schemas: BasicsDefine Content Model (5)
Right click [Person] è [Unbounded].
It sets the occurrences:1 to infinity.
XML Schemas: BasicsAdding additional levels
1. Right click [Address] è[Add child] è [Sequence]
2. Right click [Sequence] compositor è [Add child] è [Element]
3. Enter “Name”4. Final layout
1
2
3 4
XML Schemas: BasicsView Schema in TEXT mode
Notice that whenever a Sequence compositorwas inserted, the [xs:sequence] element was
inserted within the [xs:complexType] element.
A complex type element is one which contains attributes or elements.
XML Schemas: BasicsDefine [Name] as [xs:string]
Click the [Name] element.
In ‘Details’Entry Helper, from the dropdown menu of the [type] combo
box, select the [xs:string] entry.
In text mode, [type=“xs:string”] was added in [Name] element.
XML Schemas: BasicsAdd element with Drag-and-Drop
Click the [Name] element and hold down the [Ctrl] key, and drag-and-
drop the element box with the mouse. New element, [Name] is duplicated.
Do it once again therefore, there are three elements for the [Address].
XML Schemas: BasicsName the Duplicated Elements
Double click the duplicated elements
one by one and name them “Street”and “City”respectively.
So that [Address] element has a
sequence of [Name], [Street] and [City]
elements.
[Schema design] è[Configure view… ], then click [Append]
icon
XML Schemas: BasicsConfigure Content Model View (1)
From dropdown menu, select [type], then for each element
select [xs:string]
XML Schemas: BasicsConfigure Content Model View (2)
XML Schemas: BasicsComplete the Basic Schema
1. Right click [Person] è [Add child] è [Sequence]. 2. Right sequence compositorè [Add child] è
[Element].3. Enter “First”as the name.4. Choose [xs:string] as the data type.
1
2
3
4
XML Schemas: BasicsComplete the Basic Schema (2)
Add the following [Last], [Title], [PhoneExt] and [Email].
XML Schemas: BasicsComplete the Basic Schema (3)
Make an element optional. Right click the [Title] element and select [Optional]. In the [Details] Entry Helper, we can see [minOcc] = 0and [maxOcc] = 1, indicating that
the element is optional.
XML Schemas: BasicsComplete the Basic Schema (4)Change data type from [xs:string] to [xs:integer] for [PhoneExt] element.
Click on [PhoneExt], press [tab] and open the dropdown menu. Then, choose [xs:integer] instead of [xs:string]. In the [Facets] Entry Helper, double-click in the [maxIncl] field and enter “99”. This defines that all
phone extensions up to, and including 99 are valid.
[File] è [Save] to save the changes to the schema
XML Schemas: AdvancedWork with Complex Type
Right click [Address] è[Make Global] è[Complex type].
Then a global complex type called [AddressType]
is created.
XML Schemas: AdvancedSchema Overview
Click [Display All Globals] icon to return to the Schema Overview.
XML Schemas: AdvancedExtend Complex Type (1)
1. Click [Append] icon è [Complex Type] to new a component.
2. Enter “US-Address”
1
2
XML Schemas: AdvancedExtend Complex Type (2)
1. Click [Content Model View] icon of [US-Address]
2. In [Details] entry helper, click the [base] combo box and select [AddressType]
1
2
XML Schemas: AdvancedUS-Address uses AddressType
XML Schemas: AdvancedExtend the AddressType
1. Right click [US-Address] è [Add child] è [Sequence]2. Right click [Sequence compositor] è [Add child] è
[Element]3. Enter “Zip”and select [xs:positiveInteger] as type4. Final view
1
2
4
3
XML Schemas: AdvancedCreate a Global Simple Type (1)
1
2
3
1. Click [Append] icon2. Select [Simple Type]3. Enter “US-State”as the name
XML Schemas: AdvancedCreate a Global Simple Type (2)
In [Details] entry helper, open [restr] dropdown
menu, select [xs:string]
XML Schemas: AdvancedApply [US-State] in [US-Address]
1. Switch to [Component Model View] of [US-Address]
2. Right click the lower [sequence compositor] è [Add child] è[Element]
3. Enter “State”as the name4. Select [US-State] as the data type
XML Schemas: AdvancedCreate 2nd Complex Type
Try this out by yourself, to create the second Complex Type, [UK-Address]
XML Schemas: AdvancedReference Global Element (1)
Right click [Person] è [Make Global] è [Element]A small link arrow icon appears in the [Person] element, showing that this element now references the globally declared [Person] element.
XML Schemas: AdvancedReference Global Element (2)
In the [Details] Entry Helper”, the [isRef] check box is now activated.
In the [Components] box, [Person] element is added.
XML Schemas: AdvancedAttributes & Attribute Enumerations (1)
1. Switch to Schema Overview, click [Person] element to make it active
2. Choose [Attributes] tag
3. Click [Append] icon
4. Select [Attribute]
1
43
2
XML Schemas: AdvancedAttributes & Attribute Enumerations (2)
1
2 3
1. Enter “Manager”as the attribute name in the Name field.
2. In the [Type] combo box select [xs:boolean]
3. In the [Use] combo box select [required]
XML Schemas: AdvancedAttributes & Attribute Enumerations (3)
1
1. Repeat previous procedures to create [Programmer]
2. Again, create [Degree] but with Type=xs:string
3. In [Facets] box, choose [Enumerations] tag
4. Add “BA”, “MA”& “PhD”as the enumeration values
2
3
4
XML Schemas: AdvancedSave the Schema
Check that [attributes] are added as below figure.Remember to save the scheme ([File] è [Save]).
Also, save as a new file, “AddressLast.xsd”.
XML Schemas: AdvancedReview
XML Schemas: AdvancedSchema DocumentationClick [Schema design] è [Generate Documentation… ]
Select [HTML], if you want to have an html document.
Or, you may have a Microsoft Word document or even a RTF document
by choosing different radio button of [Output format].
Give it a name to save(e.g. AddressFirst.html).
XML Schemas: AdvancedLook at the Page
Create XML File
[File] è [New] è [XML Document]
Create XML FileChoose Schema File
Select [Schema].
Then, choose “AddressLast.xsd”as the schema file.
Create XML FileGrid View
Check the [Grid] view.
Click [Down] arrow to expand and view the details.
Create XML FileAdd Attribute
Right click on [Name] è [Insert] è [Attribute]
[= xs:type] is added, enter “US-Address”
Create XML FileEnter other details
Enter the following:“US dependency” for [<> Name],“Noble Ave” for [<> Street], and
“Dallas” for [<> City]
Create XML FileValidate the File
Check the “Well-formedness”and “Validate XML” by pressing the
icons belowor
[F7] to check the “Well-formedness”or
[F8] to check “Validate XML”
Element with “!”next to it means that the element
should be included in the form (XML document).
Create XML FileFile Check Results
“Well-formedness”check is OK.
“Validate XML”check is not OK because some required fields missed.
Create XML FileCorrect the File
Double click [<>!Zip] to add the [<> Zip] attribute in [Address]
Note that we need to add [<>!State] too.
So, double click on it too.
Create XML FileEnter Some Data
[<>Zip] and [<>State] are added.
Also, enter “04812” for [Zip] and “Texas” for [State]
Create XML FileEnter Data in Text View
When “<” is entered, “<> Person” appears at once. Click on it, {Person Manager=“”} is automatically added.
Type “t”and then choose [true] from the box.
Create XML FileEnter Details of Rest
Press the spacebar at the end of the line and then select [= Degree] from the box.
Type “b”and then choose [BA] from the list. Press the spacebar at the end of the line and then select [= Programmer] from the box.
Type “f”and then choose [false].
Create XML FileCheck Inputs
Type “f”and then choose [false]. Type “>”at the end of the line.
When “>” is entered, the rest elements are added
automatically and together with the end tag “</Person>”.
Check the inputs at the [Grid] view. It should be viewed as the figure next.
Create XML FileAdd More [Person] (1)
Add more [Person]. First click on [Person] area and then double click [<> Person] under [Elements] window.
Create XML FileAdd More [Person] (2)
Change the view by clicking the [Table] icon or press [F12] key.
Create XML FileAdd More [Person] (3)
Double click [= Degree] and [= Programmer] to add the two attributes.
Double click the box to choose a value from the list or enter value
directly.
Create XML FileAdd More [Person] (4)
Double click [<> Person] to new one more row (record).
Add details as below figure.
Create XML FileCheck Again the Validation
Press [F7] to check the “Well-formedness”.
Press [F8] to check the “Validate XML”.
Both checks arePassed
this time.
Create XML FileSave the File
Remember to save your work.
For example, save it as “Company_org.xml”.
Create XML File from Database- Microsoft Access (1)
Click [Convert] è [Create XML Schema from DB Structure]
Check [Microsoft Access (ADO)]
Click [Next]
Create XML File from Database- Microsoft Access (2)
Use [Browse] button to locate the database file
(DB2schema.mdb),then click [Next]
Create XML File from Database- Microsoft Access (3)
Check [User Tables]
Press [Import]
Create XML File from Database- Microsoft Access (4)
The four tables of the database file are now
converted into four elements in the XML schema
Create XML File from Database- Microsoft Access (5)
Check the [Division] element.
Create XML File from Database- Microsoft Access (6)
The generated schema appears in the Schema Design View.
Click the “Identity constraints” tab, to see the keyref and key fields of
the respective elements.
[key] refers to the [PrimaryKey] field of [Division] itself.
[keyref] refers to [ForeignKey] fields of both [Person] and [VIP]
Create XML File from Database- Microsoft Access (7)
View the content model of [Altova]
Create XML File from Database- Microsoft Access (8)
Details on lower levels
Create XML File from Database- Microsoft Access (9)
Select [Convert] è [Create XML Schema from DB Structure]
Select [IBM DB2 (ODBC)] è [Next]
Create XML File from Database- IBM DB2 (1)
Select [Create a new Data Source Name (DSN) with the driver:] and [IBM DB2 ODBC
DRIVER] è [Next]
Create XML File from Database- IBM DB2 (2)
Register a [Data source name]. For example, [db2source] is used and given “DB2 Sample
Source”as Description.
Create XML File from Database- IBM DB2 (3)
Enter [User ID] and [Password] to connect to the
database .
From the table list, check tables which will be imported into the XML Schema. For
example, check both [DEPARTMENT] and
[EMPLOYEE].
Create XML File from Database- IBM DB2 (4)
In Schema Overview, click [Identity
constraints] tab to see the [keyref] and [key]
fields of respective elements.
Create XML File from Database- IBM DB2 (5)
Check[Content Model]
view
Create XML File from Database- IBM DB2 (6)
Check [Validation] of
both [well-formedness] and [validate
XML].
Create XML File from Database- IBM DB2 (7)
Check the schema in [Text] view.
Remember to save the Schema.
[File] è [Save] to save the schema. For
example, save it as “db2example.xsd”.
Create XML File from Database- IBM DB2 (8)
XML Tutorial
Any question?
XML Tutorial
Good-bye.