• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Schema validation problem

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.

Can anyone please help?

Thanks & Regards,
Subhash
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Schema spec says

For all �atomic� datatypes other than string (and types �derived� by �restriction� from it) the value of whiteSpace is collapse and cannot be changed by a schema author;


I'm no Schema expert, but I think this says that those leading and trailing spaces will automatically be removed. Since you posted the question you must think the behaviour you described is a problem. Why do you think that?
 
Subhash srivastava
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Paul..
Here are the XSD details...
<xsd:element name='EZ' minOccurs='0' maxOccurs='1'>
<xsd:simpleType>
<xsd:restriction base='xsd:nonNegativeInteger'>
<xsd:maxInclusive value='9999' />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>

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.

Can any one please help....

Thanks in Advance

Rajeev

Originally posted by Subhash srivastava:
Hi,

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.

Can anyone please help?

Thanks & Regards,
Subhash

 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So if I understand that you correctly, you think there's a problem only because you have these requirements which say it's a problem?

I guess, if you have requirements which can't be implemented via schemas, you're going to have to figure out some other way to implement them. If it were me I would go back to the people who wrote those requirements and inquire about whether they really need to prevent the leading and trailing blanks. That looks somewhat pointless to me.

You might also investigate whether the parser will actually remove the leading and trailing blanks from a validated document. If it will, that definitely makes the requirement pointless.
 
Subhash srivastava
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thanks for the reply.
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.

Thanks,
Rajeev
 
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic