OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Will "AT&T" fit in a string attribute with maxLength="4"?

[ Lists Home | Date Index | Thread Index ]
  • To: "'Xml-Dev (E-mail)" <xml-dev@lists.xml.org>
  • Subject: Will "AT&T" fit in a string attribute with maxLength="4"?
  • From: "Zielinski, Marek" <mzielinski@gma.com>
  • Date: Tue, 20 May 2003 13:47:12 -0400

I am trying to define restrictions on string lengths using Schema. The data
actually comes from databases, and is exchanged between two different
systems. I encountered a snag: when the string contains one of the reserved
characters, like "&", the parser automatically translates it into an entity,
e.g. &amp;. This increases the length of the string, and now the string does
not fit; the validator (I am using XMLSpy) rejects it as too long.  

I could add a couple of characters to the maxLength restriction, but this
defeats the purpose of length limit. Besides, to be safe I would need to
make the limit about 4 times larger than the intended limitation on the
actual string length. (i.e. if want to limit string to 4 chars, and the
string happens to be "&&&&")

Any solution? Any way to make the parser decode the entity before checking
the string length? 

-Marek Zielinski
GMA

Example below: the XML does not validate, although the string is originally
'AT&T'.

Sample XML:
<PhoneCompany Name="AT&amp;T"/>

Sample Schema:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="PhoneCompany">
		<xs:complexType>
			<xs:attribute name="Name" use="optional">
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:maxLength value="4"/>
					</xs:restriction>
				</xs:simpleType>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
</xs:schema>




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS