DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> XML學習教程 >> XML詳解 >> Validating XML Schemas
Validating XML Schemas
編輯:XML詳解     

The goal of this tutorial is to revIEw the functionality that you can use to validate your schema files.

  Prerequisites

  Creating a Project and Opening a Sample XML Schema

  (Optional) Exploring XML Schemas

  Working With XML Schemas Using the Schema VIEw

  (Optional) Working With XML Schemas Using the Design VIEw

  (Optional) Analyzing XML Schemas

  (Optional) RetrIEving and Referencing External XML Resources

  (Optional) Applying Design Patterns to XML Schema Files

  Working With Broken XML Schema Files

  To demonstrate validation, you will insert an error in one of the XML schema files in the mySchemaPrj project and then use the validate function to find the error and see what happens when a schema is not valid.

  To insert an error:

  If mySchemaPrj is not open in the IDE, open it now and then open the newLoanApplication schema file.

  Maximize the vIEw by right-clicking the tab for the file and choosing Maximize Window from the pop-up menu.

  Maximizing the view lets you see more information about the schema in the column view of the Schema vIEw.

  In the first column of the Schema vIEw, select the Elements node.

  In the second column of the Schema vIEw, select the autoLoanApplication node, right-click and choose Go To > Source.

  In the Source vIEw, remove the closing bracket from the autoLoanApplication element definition.

Validating XML Schemas

  In the editor toolbar, click the Check XML button Validating XML Schemas to verify that you introduced an XML error.

  The Output - XML check window opens with the result of the check, which shows that one error was found. Messages similar to the ones shown below appear in the Output - XML Check window:

XML checking started.
Checking file:/C:/myProjects/mySchemaPrj/src/newLoanApplication.xsd...
Element type "xs:element" must be followed by either attribute specifications, ">" or "/>". [10]
XML checking finished.

  In the editor toolbar, click the Validate XML button Validating XML Schemas to validate the XML.

  The Output - XML check window refreshes to show a validation error. Messages similar to the ones shown below appear in the Output - XML Check window:

XML validation started.
C:/myProjects/mySchemaPrj/src/newLoanApplication.xsd:10,8
Error: Element type "xs:element" must be followed by either attribute specifications, ">" or "/>". [10]
1 Error(s), 0 Warning(s).
XML validation finished.

To work with a broken schema file:

  Click the Schema button in the editor toolbar to switch to the Schema vIEw.

  The schema content does not appear in the Schema view. Instead, the following message appears in the middle of the vIEw:

<The schema is not well-formed. Please fix it in the source vIEw.>

  Click the Source button to switch back to the Source vIEw.

  Add the closing bracket in the autoLoanApplication element definition to fix the problem.

  Note: If you have code completion functionality turned on, the following happens as soon as you type the closing bracket (>): the IDE adds the following code to close the element:

  </xs:element>. In this case, delete the </xs:element> string.

  The autoLoanApplication is already terminated further down in the source file.

  Verify that you fixed the error by doing the following:

  In the editor toolbar, click the Check XML button Validating XML Schemas to verify that you fixed the error.

  The Output - XML check window refreshes with the result of the check, which shows that no errors were found.

  In the editor toolbar, click the Validate XML button Validating XML Schemas to validate the XML.

  The Output - XML check window refreshes to show that there are no validation errors.

  Click the Schema button in the editor toolbar to switch to the Schema vIEw.

  Notice that the schema content now appears in the Schema vIEw because you fixed the error in the source.

  Close the Output window by clicking the Close button in the window's title bar.

  From the IDE main menu, choose File > Save All.


 


 

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved