Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Schema Whitespace Restriction

 
Jan Jani
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there any way to put a constraint on a schema element so that it does not allow whitespaces?
~Jani
 
Elliotte Rusty Harold
author
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, though exactly how best to do it depends on what you're trying. In the W33C XML Schema Language, the simplest is probably to define your own subtype of xsd:string using the pattern facet and a regular expression that forbids all white space. For example:
<xsd:simpleType name="nospace">
<xsd:restriction base="xsd:string">
<xsd :pattern value="[^\r\n\t ]*"/>
</xsd:restriction>
</xsd:simpleType>

or a little more Unicode savvy:
<xsd:simpleType name="nospace">
<xsd:restriction base="xsd:string">
<xsd :pattern value="[^\r\n\t \p{Z}]*"/>
</xsd:restriction>
</xsd:simpleType>

I'm not sure if that's going to get through unscathed, because the regular expressions use square brackets like UBB, and this system does not allow me to preview or edit my posts, but you can find more details in the XML Bible at http://www.cafeconleche.org/books/biblegold/chapters/ch24.html
[Edited by Gregg Bolinger to disable smilies]
[ February 25, 2004: Message edited by: Gregg Bolinger ]
 
Elliotte Rusty Harold
author
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the brackets came through OK, but the colon-p's in xsd:pattern changed into smiley faces. Weird.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, take a look at this.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this system does not allow me to preview or edit my posts
FYI...
We do allow 'Edit' of the posts. Please use the 'Notepad' icon
on your post to edit or delete. Also, to disable the 'faces'
you can toggle-on the 'Disable Smiles in this post' at the bottom.
Thanks.
- m
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic