users@jaxb.java.net

White Space Elimination Problem

From: Marcus Walls <marcus.walls_at_ASPECTIVE.COM>
Date: Fri, 10 Jan 2003 06:13:09 -0700

Apologies if this is a newbie question, but I am indeed new to JAXB and can't find an answer to my question in the various docs I've seen.

I have an element which must contain string data. It must not consist of just whitespace, and it is bounded in length. My current proprietary code performs a trim() on the element and then sets the property of a java object.

I'd like to do this in JAXB, and I have tried the following:

  <xsd:element name="surname">
    <xsd:simpleType>
      <xsd:restriction base="xsd:string">
        <xsd:whiteSpace value="collapse"/>
        <xsd:minLength value="1"/>
        <xsd:maxLength value="255"/>
      </xsd:restriction>
    </xsd:simpleType>
  </xsd:element>

If white space processing appears to work okay (if my element contains 255 characters with lots of trailing and leading whitespace it doesn't complain) but when I call getSurname() or when I marshall the document back out again it still contains the white space.

Am I doing something wrong?

Any help gratefully received.

Thanks in advance.

Marcus Walls