aspose file tools*
The moose likes XML and Related Technologies and the fly likes Schema Whitespace Restriction 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 Whitespace Restriction" Watch "Schema Whitespace Restriction" New topic
Author

Schema Whitespace Restriction

Jan Jani
Ranch Hand

Joined: Feb 05, 2004
Posts: 35
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

Joined: Feb 25, 2004
Posts: 91
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<br />Author of <a href="http://cafe.elharo.com/web/refactoring-html/" target="_blank" rel="nofollow">Refactoring HTML</a>
Elliotte Rusty Harold
author
Ranch Hand

Joined: Feb 25, 2004
Posts: 91
Looks like the brackets came through OK, but the colon-p's in xsd:pattern changed into smiley faces. Weird.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Yep, take a look at this.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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
 
Don't get me started about those stupid light bulbs.
 
subject: Schema Whitespace Restriction