467,859 Members | 1,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,859 developers. It's quick & easy.

minLength and maxLength

ray
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

Nov 12 '05 #1
  • viewed: 2252
Share:
7 Replies
Please post your XML that you are trying to validate with the given schema.

Thanks.

<ra*@cape.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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

Nov 12 '05 #2
ray
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">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AddAuth" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Account_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:integer ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Account_Contact_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Acct_Location_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Num_Of_Employees" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Department" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Salutation" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Comments" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2000" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

this is driving me simply batty. thanks for your help.

Ray

Nov 12 '05 #3


ra*@cape.com wrote:

<?xml version="1.0" ?>
- <data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="LeadXSD.xsd"> <?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">


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
http://JavaScript.FAQTs.com/
Nov 12 '05 #4
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.
<ra*@cape.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1" />
<xs:maxLength value="16" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AddAuth" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string"></xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Account_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:integer ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Account_Contact_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Acct_Location_Id" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Num_Of_Employees" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="xs:string ">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="Department" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="64" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Salutation" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Comments" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="2000" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

this is driving me simply batty. thanks for your help.

Ray

Nov 12 '05 #5
ray
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

Nov 12 '05 #6
The maxLength value of 64 should not matter, the empety element <Company/>
should NOT validate if minLength=1 in the schema for its type

<ra*@cape.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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

Nov 12 '05 #7
ray
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

Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Lovely Dola | last post: by
1 post views Thread by Don Adams | last post: by
4 posts views Thread by hardcoded | last post: by
1 post views Thread by Mel | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.