Why datatype isn't verified when validating XML with Schema?

Here is XML Schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="id" type="xs:long" />
</xs:schema>

XML file that is validated for conformance:

<?xml version="1.0" ?>
<id>invalid_data</id>

Java code that works with XML and should test conformance:

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setSchema(schemaFactory.newSchema(new File(xmlSchema)));
parser = factory.newSAXParser();
MySaxHandler handler = new MySaxHandler();
parser.parse(new File(xmlFile), handler);

During invocation of this code NumberFormatException is throwed in characters method of MySaxHandler. MySaxHandler also contains overriden methods warning, error and fatalError but they aren't executed.

I don't want this NumberFormatException being thrown. I want datatype being validated according to Schema. How do I do it?

Answers


I wonder if it's simply a timing issue. The schema validator can't test the content of the element until the end element event is reached, but the text node is reported to the ContentHandler before the end element event is reached. Try masking the exception in your application to see if the validation error gets reported a bit later.


Need Your Help

Writing a DTrace consumer in C

c freebsd dtrace

I'd like to write a C program on FreeBSD 10.1 that implements a DTrace consumer using libdtrace.

Issue with building project in XCode — ProcessPCH Error

ios xcode compiler-construction prefix

I've been having an issue compiling my project after attempting to install the Facebook SDK to the project. I've reverted the code back to it's previous state, however I'm still getting error messa...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.