File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Schema Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Schema Validation" Watch "Schema Validation" New topic

Schema Validation

Subhash srivastava

Joined: Dec 16, 2008
Posts: 4

I am new to XML and related technologies. In my application I have used and XSD that contains an element named "EZ" and its type is nonNegativeInteger with max inclusive value 9999.

we have XML file in which tag "EZ" is taking spaces with value ( For example <EZ> 3</EZ>, <EZ>3 </EZ>, <EZ> 3 </EZ>, <EZ> 3</EZ> etc). But currently these XML files are successfully validating by the parsers while it should not accept the spaces with values. According to our requirements it should be fail in schema validation. I tried <xsd:pattern> with various options but it is not working because "EZ" is defined as nonnegativeInteger.

Here are the XSD details...
<xsd:element name='EZ' minOccurs='0' maxOccurs='1'>
<xsd:restriction base='xsd:nonNegativeInteger'>
<xsd:maxInclusive value='9999' />

In xml the tag EZ containing values with spaces as shown below.
<EZ> 54 </EZ>

According to our req. it should fail in schema validation but currently it is not failing. I have used restrictions and pattern but it didn't work.

I checked but parsers are not currently removing spaces. It is accepted values with spaces i.e. " 4 " or " 3" etc. I had also tried different
pattern (([0-9]+) and many more combinations) but it didn't work. Not sure how to restrict this.

Can anyone please help?

Thanks in Advance...
I agree. Here's the link:
subject: Schema Validation
It's not a secret anymore!