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 Whitespace Restriction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Schema Whitespace Restriction" Watch "Schema Whitespace Restriction" New topic

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?
Elliotte Rusty Harold
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 ]*"/>

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

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
[Edited by Gregg Bolinger to disable smilies]
[ February 25, 2004: Message edited by: Gregg Bolinger ]

Elliotte Rusty Harold<br />Author of <a href="" target="_blank" rel="nofollow">Refactoring HTML</a>
Elliotte Rusty Harold
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

Joined: Jan 23, 2002
Posts: 11962
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
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.
- m
I agree. Here's the link:
subject: Schema Whitespace Restriction
Similar Threads
logical schema Vs physical schema
WA #1.....word association
code to validate xml which has inline schema
Roles in IT suitable for "Visual thinkers" ?
Howto validate xml schema?