DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> XML學習教程 >> XML詳解
驗證 XML 結構描述
編輯:XML詳解     

目標

本課程回顧可用來驗證結構描述檔案的功能,並示範如何找出錯誤、查看驗證訊息,以及修正不良格式。

前提條件

建議先完成建立專案、開啟範例 XML 結構描述、探索結構描述、使用結構描述檢視與設計檢視等前置課程。

建立錯誤

為了示範驗證流程,我們會在 mySchemaPrj 專案的 newLoanApplication 結構描述中故意建立一個錯誤。

  1. 若 mySchemaPrj 尚未開啟,請先在 IDE 中開啟,然後開啟 newLoanApplication 結構描述檔案。
  2. 右鍵按一下檔案頁籤,選擇最大化視窗,以便看更多結構描述資訊。
  3. 在結構描述檢視的第一欄中,選取 Elements 節點。
  4. 在第二欄中選取 autoLoanApplication,右鍵選擇 Go To > Source。
  5. 在原始碼檢視中,移除 autoLoanApplication 元素定義的結尾角括號。
移除結尾角括號

接著按一下編輯工具列上的 Check XML 按鈕,確認已建立 XML 錯誤。

Check XML 按鈕

Output - XML check 視窗會顯示檢查結果,指出找到一個錯誤。訊息可能類似:

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.

再按一下 Validate XML 按鈕,執行驗證。

Validate XML 按鈕

此時 Output - XML check 會顯示驗證錯誤:

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.

處理不良格式的結構描述

  1. 按一下編輯工具列上的 Schema 按鈕,切換到結構描述檢視。
  2. 由於檔案不是格式良好的 XML,結構描述內容不會顯示,畫面中央會出現提示:The schema is not well-formed. Please fix it in the source view.
  3. 按一下 Source 按鈕,回到原始碼檢視。
  4. 在 autoLoanApplication 元素定義中補回結尾角括號。

注意:若開啟程式碼補全功能,輸入結尾角括號後,IDE 可能自動加入 /xs:element。若 autoLoanApplication 在檔案後方已有結束標籤,請刪除自動產生的重複內容。

確認修正成功

  1. 按一下 Check XML,確認 XML 錯誤已修正。
  2. Output - XML check 會重新整理,顯示沒有錯誤。
  3. 按一下 Validate XML,確認沒有驗證錯誤。
  4. 按一下 Schema 按鈕,切回結構描述檢視。此時結構描述內容會正常顯示。
  5. 關閉 Output 視窗,並從主選單選擇 File > Save All。

透過這個流程,可以清楚區分 XML 格式檢查與結構描述驗證的差異,並知道如何在 IDE 中修正常見錯誤。

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