`
pwosboy
  • 浏览: 84202 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

Using the Validating Parser

阅读更多

It's helpful to start by defining the constants you'll use when setting the properties:

static final String JAXP_SCHEMA_LANGUAGE =
    "http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =
    "http://www.w3.org/2001/XMLSchema"; 
  SAXParserFactory factory = SAXParserFactory.newInstance();
  factory.setNamespaceAware(true);
  factory.setValidating(true); 
You'll learn more about namespaces in Validating with XML Schema. For now, understand that schema
validation is a namespace-oriented process. Because JAXP-compliant parsers are not namespace-aware
by default, it is necessary to set the property for schema validation to work.
 
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); 
setProperty没有完全明白作用,文档上写的和例子上表现的是有所出入的。
 

Experimenting with Validation Errors

Validating Parsing主要处理下面的错误
1、XML文档中没有一个有效的验证文档,比如说没有一个有效的dtd文件,DOCTYPE标签的缺失。
2、XML文档的内容和dtd描述不相符,比如(image?,title,item*)  ,如果xml中该元素的中缺失title就会报错。
3、PCDATA的问题,或者是说元素当中可不可以含有元素和字符的混合体。
 

DTD Warnings

# Providing additional declarations for entities, attributes, or notations. (Such declarations are ignored. Only the first is used. Also, note that duplicate definitions of elements always produce a fatal error when validating, as you saw earlier.) # Referencing an undeclared element type. (A validity error occurs only if the undeclared type is actually used in the XML document. A warning results when the undeclared element is referenced in the DTD.)
# Declaring attributes for undeclared element types.
# References to an undefined parameter entity when not validating. #Certain cases where the character-encoding declaration does not look right.
 
注意:Validating Error和DtD Warnings中的区别和联系。
1、如果XML没有根据dtd的限制进行编写,比如多个dtd中没有声明的元素,是errors(),反过来如果是dtd中定义的元素或者是属性没有在xml中有所体现,那么就会有warning。
2、warning大部分是发生在dtd本身。除了上述错误,经常是一些重复定义,或者是给未定义的元素定义属性等等这样的错误。
分享到:
评论

相关推荐

    MacOS:Xerces

    A shared library is provided for parsing, generating, manipulating, and validating XML documents using the DOM, SAX, and SAX2 APIs. For an introduction to programming with Xerces-C++ refer to the ...

    C#中Validating和Validated事件

    C#中的 Validating 和 Validated 事件 在 C# 中,Validating 和 Validated 事件是两个重要的事件,它们在控件的数据验证过程中扮演着关键角色。这些事件通常用于验证用户输入的数据,以确保输入的数据符合要求。 ...

    UML for the C programming language

    Validating the design using the UML model is crucial for ensuring that the system meets its requirements and performs as expected. Techniques such as simulation and formal verification can be employed...

    Using Perl For Web Programming.pdf

    Validating the User H G CONTENTS http://docs.rinet.ru:8080/Using_Perl5_in_Web/ (5 of 24) [2/17/2007 1:22:34 PM] Logging Out H Managing Session Data Storing Session Data H Retrieving Session Data H...

    Learning ASP.NET Core MVC Programming

    Integrating your application with Bootstrap, validating user input, interacting with databases, and deploying your application are some of the things that you will be able to execute with this fast-...

    Python - Fast XML parsing

    The xml.parsers.expat module is a Python interface to the Expat non-validating XML parser. The module provides a single extension type, xmlparser, that represents the current state of an XML parser. ...

    validating the safty of cooking procedures

    美食该如何制作?食品安全以什么为标准?...这么一份validating the safty of cooki...该文档为validating the safty of cooking procedures,是一份很不错的参考资料,具有较高参考价值,感兴趣的可以下载看看

    xerces-c-3.0.0.zip

    xerces-c-3.0.0.zip Xerces-C++ is a validating XML parser written in a... A shared library is provided for parsing, generating, manipulating, and validating XML documents using the DOM, SAX, and SAX2 APIs

    alamgirfiles.zip_is proposed power_non linear load_power control

    The fuzzy logic control based battery management system has been designed for effective power ... Finally, simulation results are uated and validating the effectiveness of the proposed controller.

    Specification by Example - How Successful Teams Deliver the Right Software

    6. **Validating Frequently**: Regular validation checks are performed throughout the development cycle, ensuring that the software remains aligned with the specified requirements. 7. **Evolving a ...

    HTML5 Games

    - **Implementing the Rules**: Coding the rules for validating swaps, detecting chains, and refilling the grid after a move. - **Swapping Jewels**: Implementing the functionality for swapping jewels on...

    人工智能-深度学习-有源电力滤波器控制系统研究.pdf

    Experimental studies are initially conducted on the parallel active power filter, validating the effectiveness of the proposed methodologies. In conclusion, the research presented in "人工智能-深度...

    R.Machine.Learning.Essentials.178398774X

    You will learn the three steps to build an effective machine learning solution, which are exploring the data, building the solution, and validating the results. The book will demonstrate each step, ...

    Laravel 5.x Cookbook (Packt 2016)

    Using the Facade pattern 27 Using private packages 29 Chapter 3: Routing 33 Introduction 33 Building an API / JSON based route for searching 33 Testing your route in PHPUnit 37 Building a view based ...

    远程控制软件UltraVNC源码

    # Validating that the code that was reviewed is indeed the code being # checked in (using the bug-id number or a seperate review # number to identify this particular code set.). # # If any of the ...

    UML and the Unified Process.pdf

    formed rules (using the Object Constraint Language and precise text) and precise text. The formalization of UML is still an open problem. Many works have been done to formalize parts of the language ...

    Excel.2013.Working.with.Data.Ranges.and.Tables

    identify multiple ways to define an Excel table using buttons on the HOME and INSERT tabs, the Quick Analysis feature, a keyboard shortcut and by formatting a data range as a table, and recognize ways...

    Laravel开发-validating 模型数据自动验证

    `validating`是一个流行的第三方包,它为Laravel提供了模型数据的自动验证功能,极大地简化了模型验证的流程。这个包通常通过引入一个trait(特性)来实现,使得在保存数据到数据库之前,模型能够自动进行验证。 ...

    SAS.9.2.SQL.Procedure.Users.Guide

    After grouping data, you can further filter the results using the HAVING clause, which filters the results of a GROUP BY operation. For example: ```sql SELECT column1, COUNT(*) FROM table_name GROUP ...

Global site tag (gtag.js) - Google Analytics