Friday, July 07, 2006

The type attribute cannot be present with either simpleType or complexType

Okay, I was struggling with this one for a while and couldn't find any answers on the net and it's one of those things that turn out making you feel stupid.

My xsd schema wouldn't validate. It failed with the error message mentioned on the title of this post: "The type attribute cannot be present with either simpleType or complexType." The relevant part of my schema was:


<xs:complexType name="ct_tuning">
<xs:attribute name="style" type="xs:string" use="required" />
<xs:attribute name="key" type="xs:string" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[a-gA-G]" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>

</xs:complexType>


Now what could possibly be wrong with this that???

Well, it turns out the error message is not helpful at all and doesn't make any sense.

The problem with this snippet is that the attribute has already been given a type.If you notice the declaration in bold you'll notice that the attribute named "key" has been declared with type="xs:string". By declaring the simpleType underneath I am declaring its type twice.

Deleting the type="xs:string" from the declaration solved the problem.

19 Comments:

At 12:43 pm, Blogger Rob said...

thanks, I had the same issue!

 
At 3:13 pm, Blogger Unknown said...

thanks it was helpful!

 
At 5:02 pm, Blogger Diego Jancic said...

Thanks! Really useful ;-)

 
At 4:16 pm, Blogger Unknown said...

Thanks a bunch!

 
At 10:26 am, Anonymous Anonymous said...

thanks a lot, saved me a lot of time :)))

 
At 5:10 am, Anonymous Archer said...

Thanks this solved my problem, and I don't feel so stupid now :P

 
At 11:12 am, Blogger Hari said...

saved my day!!

 
At 10:14 am, Anonymous Avi said...

+1 from me!
Big up yourself!
Thanks!

 
At 10:51 pm, Anonymous azhkri said...

Article really help. Thank you.

 
At 9:56 am, Blogger Vinod CS said...

Thank you very much, I was struggling to get any clue on this problem

 
At 2:12 pm, Anonymous Anonymous said...

Simple fix, these are the ones I like most! Thanks :)

 
At 11:09 am, Anonymous Anonymous said...

thanks!

 
At 10:17 am, Anonymous Anonymous said...

Bravo!

 
At 11:25 am, Anonymous Anonymous said...

Excellent post. I was checking continuously this blog and
I'm impressed! Extremely helpful information particularly the last part :) I care for such info much. I was seeking this particular info for a long time. Thank you and good luck.

Review my blog post ... s2000 spoiler

 
At 10:38 am, Anonymous Anonymous said...

Fantastic web site. Lots of helpful information here.
I'm sending it to some pals ans additionally sharing in delicious. And of course, thank you to your effort!

my homepage :: raspberry ketone diet

 
At 1:40 pm, Anonymous Anonymous said...

Thanks - I know it's 7 years later than everyone elses posts but this just helped me too!
Thank you

 
At 8:47 am, Blogger Unknown said...

thanks!

 
At 11:08 am, Anonymous Arunkumar Subbiah said...

After searching everywhere in the internet, it is your post helped me to resolve it. Thanks

 
At 5:24 pm, Anonymous Anonymous said...

Thank you so much, your simple explanation of the error made me realize what was wrong with my code after so many hours and searches, :)

 

Post a Comment

<< Home