FeaturesPluginsDocs & SupportCommunityPartners

验证 XML Schemas

返回XML 模式工具入门

本教程的目标是回顾您可以使用检验您的 Schema 文件的功能。

回到页首


处理损坏的 XML Schema 文件

为了掩饰验证,您将向 mySchemaPrj 项目中的 XML Schema 文件中的一个添加一个错误, 然后使用验证功能找到错误,情怯观察当 Schema 文件无效的时候会发生什么。

插入一个错误:

  1. 如果 mySchemaPrj 未在 IDE 中打开,请现在打开它然后打开 Schema 文件 newLoanApplication
  2. 右键单击文件的标签然后在弹出菜单中选择“窗口最大化”来最大化视窗。
    最大化视窗可以使您看到更多关于 Schema 视窗中 Schema 列视图的信息。
  3. 在 Schema 视窗的第一列中,选择 Elements 节点。
  4. 在 Schema 视窗的第二列中,选择 autoLoanApplication 节点名右键单击并选择 转到 > 源。
  5. 在源视窗中,删除 autoLoanApplication 元素定义中的 closing bracket。

    从 autoLoanApplication 定义中删除 closing bracket

  6. 在编辑器工具栏中,单击检查 XML 按钮 检查 XML 检查出您所导致的 XML 错误。
    检验出一个错误被找到的“输出 - XML 检查窗口”将被打开。一个与下方显示的相似的信息将出现在“输出 - XML 检查窗口”中:
    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.
    
  7. 在编辑器工具栏中,单击验证 XML 按钮 验证 XML来验证 XML。
    “输出 - XML 检查窗口”将显示一个验证错误。一个与下方显示的相似的信息将出现在“输出 - XML 检查窗口”中:
    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.
    

处理损坏的 Schema 文件:

  1. 在编辑器工具栏中单击 Schema 按钮切换到 Schema 视窗。
    Schema 内容在 Schema 视图中没有出现。取而代之,在试图的中间出现如下的信息:
    <The Schema is not well-formed. Please fix it in the source view.>
  2. 单击源按钮切换回源视窗。
  3. autoLoanApplication 元素定义添加 closing bracket 来修复错误。
    提示: 如果您将“代码完成功能”开启,在您键入 closing bracket (>) 的同时会发生:IDE 添加如下代码关闭这个元素:
    </xs:element>. 这时,请删除字符串 </xs:element>
    autoLoanApplication 已经在源文件处终止。
  4. 按照如下步骤检验您修复的错误:
    1. 在编辑器工具栏中,单击检查 XML 按钮检查 XML来检验您已修复的错误。
      “输出 - XML 检查窗口”刷新显示检查的结果未找到错误。
    2. 在编辑器工具栏中,单击验证 XML 按钮验证 XML来验证 XML 。
      “输出 - XML 检查窗口”刷新显示没有验证错误。
    3. 在编辑器工具栏中单击 Schema 按钮切换至 Schema 查看。
      注意 Schema 内容现在出现在 Schema 视窗中因为您已经在源中修复了这个错误。
  5. 单击窗口标题栏处的关闭按钮关闭输出窗口。
  6. 在 IDE 主菜单中, 选择 文件 > 全部保存。

Bookmark this page

del.icio.us furl simpy slashdot technorati digg
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by