views:

28

answers:

1

Using XSD, is it possible to constrain the total text within a Node. In the example below, I want Address Node content to be restricted to 255 characters.

<Address>
    <Line1>Text</Line1>
    <Line2>Text</Line2>
    <City></City>
    <Street></Street>
    <State></State>
    <Country></Country>
</Address>

So, if I only had Line1 and Line2 in my address and City, Street, State and Country were empty, then Line1 could be 254 characters and Line2 will be 1 character.

Is it possible to set such constraints/restrictions within the xsd itself?

A: 

You can constrain the text with a single element to be a given size i.e.

            <xs:element name="Line1">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="255" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>

But you can't say Line1 + line2 + City ... < 255.

Sprotty