all groups > dotnet xml > march 2005 >
You're in the

dotnet xml

group:

minLength and maxLength


minLength and maxLength ray NO[at]SPAM cape.com
3/28/2005 12:28:18 PM
dotnet xml:
My xsd has the following element:
<xs:element name="Company" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="5" />
</xs:restriction>
</xs:simpleType>
</xs:element>

when i change the maxLength to what i really want(64) it seems to
ignore both. Is it me or is there something i am not seeing. Below is
my validation routine in my .net program.
XmlTextReader xml = new XmlTextReader(SaveLocation);
XmlValidatingReader xsd = new XmlValidatingReader(xml);
xsd.ValidationType = ValidationType.Schema;
xsd.ValidationEventHandler += new
ValidationEventHandler(MyValidationEventHandler);
while (xsd.Read())
{
if(xsd.NodeType == XmlNodeType.Element)
{
switch(xsd.Name)
{
case "data":
break;
case "lead":
numOfleadNodes +=1;
columnCount=0;
break;
default:
columnCount +=1;
break;
}
string parentElementName = xsd.Name;
columnName=xsd.AttributeCount.ToString();
}
}
xsd.Close();
xml.Close();


thanks

Ray
Re: minLength and maxLength Zafar Abbas [MSFT]
3/28/2005 2:45:35 PM
Please post your XML that you are trying to validate with the given schema.

Thanks.

[quoted text, click to view]

Re: minLength and maxLength ray NO[at]SPAM cape.com
3/28/2005 2:54:13 PM
the xml file:


<?xml version="1.0" ?>
- <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="LeadXSD.xsd">
- <lead>
<Company />
<Address1>sssssssssss</Address1>
<Address2 />
<City />
<State />
<Postal_Code_Id>B-9200</Postal_Code_Id>
<Country>Belgium</Country>
<Country_Id />
<First_Name />
<Last_Name />
<Email />
<Title>Application Manager</Title>
<Phone_Country_Code>32</Phone_Country_Code>
<Phone_Area_Code />
<Phone>3 8869801</Phone>
<Ext />
<Fax_Country_Code />
<Fax_Area_Code />
<Fax />
<Rep>VANDEP</Rep>
<Salesteam />
<Territory_Id />
<Lead_Status>To Be Qualified</Lead_Status>
<Priority>3 - Medium</Priority>
<AddAuth />
<Account_Id>1</Account_Id>
<Account_Contact_Id />
<Acct_Location_Id />
<Num_Of_Employees />
<Department />
<Salutation>Mr</Salutation>
<Comments />
</lead>
</data>

the xsd file:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:simpleType name="CompanyString">
<xs:annotation>
<xs:documentation>Company string</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="5" />
</xs:restriction>
</xs:simpleType>
<xs:element name="data">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="lead">
<xs:complexType>
<xs:sequence>
<xs:element name="Company" minOccurs="0"
type="CompanyString"></xs:element>
<xs:element name="Address1" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="64" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Address2" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="City" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="State" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Postal_Code_Id" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Country" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Country_Id" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="30" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="First_Name" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Last_Name" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Email" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="132" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Title" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Phone_Country_Code" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="5" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Phone_Area_Code" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Phone" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Ext" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Fax_Country_Code" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Fax_Area_Code" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Fax" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Rep" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Salesteam" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="80" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Territory_Id" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Lead_Status" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="20" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Priority" minOccurs="0">
Re: minLength and maxLength Zafar Abbas [MSFT]
3/29/2005 9:55:06 AM
There are problems with the XML that you posted. In the XML, Company,
First_Name and Last_Name have no content and in the schema they have a
minLength facet of 1. So this will not validate.

I fixed that by putting minLength=0 on the types, and it validates fine for
me for all values of maxLength (yes I tried 64 as well). What error or
behavior do you see which leads you to believe that there is a problem?

Thanks.


[quoted text, click to view]
Re: minLength and maxLength ray NO[at]SPAM cape.com
3/29/2005 12:38:19 PM
first off, thanks for all the help. it seems that if i have a minLength
of 1 and a maxLength of 64 and the xml for the company field has no
data it still passes the xsd validation. it seems to me that if company
has nothing in it and i have a minlength of 1 it should fail? is this
correct?

Ray
Re: minLength and maxLength Martin Honnen
3/29/2005 5:55:49 PM


[quoted text, click to view]


[quoted text, click to view]

You need
elementFormDefault="unqualified"
if you want your elements to be in no namespace.
Not sure whether that causes your problem but you should fix that.

--

Martin Honnen
Re: minLength and maxLength Zafar Abbas [MSFT]
3/30/2005 2:57:59 PM
The maxLength value of 64 should not matter, the empety element <Company/>
should NOT validate if minLength=1 in the schema for its type

[quoted text, click to view]

Re: minLength and maxLength ray NO[at]SPAM cape.com
3/31/2005 7:32:46 AM
But it does and i have no idea why. At this point i am really stressing
about this and don't know what to do. Has anyone else come across this
before?

Thanks Zafar for your time.

Ray
AddThis Social Bookmark Button