Walbury’s Blog

MS DotNet 2005 xml validator error

Hm, yep another one, but this one’s so obscure that I’m doubtful it has (or will!) be encountered by anyone – ever! For starters it only occurs when there are 2 instances of the same attribute name, one ref’ed and one inline, something that is VERY unlikely to happen – and extermely poor design (hey I’m testing!). Additionally the schema has no targetNamespace, hence, as it is using global references (it) needs to have a blank namespace (ie xmlns=””) added to these attributes to validate (one because it’s a reference, the other because it is a simpleType, so both global); and finally the error occurs when an additional namespace is present, even if unused (needless to say it also occurs if it IS used, so is not merely an esoteric issue…)
In full this can be demonstrated by using the below schema;

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns="http://example.org/ord" xmlns:other="http://anyotherNS" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<!-- removing the (unused) xmlns:other="http://anyotherNS" makes the sample file valid -->
	<xsd:element name="order">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="ProductTypeD">
					<xsd:complexType mixed="true">
						<xsd:sequence/>
						<xsd:attribute ref="gAttTestInlineAGref" xmlns=""/>
					</xsd:complexType>
				</xsd:element>
				<xsd:element name="ProductTypeE">
					<xsd:complexType mixed="true">
						<xsd:sequence/>
						<xsd:attribute name="gAttTestInlineAGref" type="string7" xmlns=""/>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
		</xsd:complexType>
	</xsd:element>
	<xsd:attribute name="gAttTestInlineAGref">
		<xsd:simpleType>
			<xsd:restriction base="xsd:string">
				<xsd:maxLength value="2"/>
			</xsd:restriction>
		</xsd:simpleType>
	</xsd:attribute>
	<xsd:simpleType name="string7">
		<xsd:restriction base="xsd:string">
			<xsd:maxLength value="7"/>
		</xsd:restriction>
	</xsd:simpleType>
</xsd:schema>

and the instance file;

<?xml version="1.0" encoding="utf-8"?><order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance":noNamespaceSchemaLocation="orderProd_NYNQU_QU.xsd">
<ProductTypeD gAttTestInlineAGref="AB" />
<ProductTypeE gAttTestInlineAGref="abcdefg" />
</order>

The error is: The ‘gAttTestInlineAGref’ attribute is invalid – The value ‘abcdefg’ is invalid according to its datatype ‘String’ – The actual length is greater than the MaxLength value.
Path: order[1]/ProductTypeE[1]/@gAttTestInlineAGref
This is incorrect – ProductTypeE/@gAttTestInlineAGref is simpleType string7 so is ok.
If we take out the unused additional namespace (xmlns:other=”http://anyotherNS&#8221;) the error disappears. Interestingly MSXML2 does not get this error. Also it seems to have been fixed in VS2008 (so why am I writing this? Just a record of obscure errors that I’ve observed along the way I guess… Oh, and the fact that I really, really prefer VS2005 to the later VS’s – debugging is just oh, so slow. Maybe I’ll do a post and benchmark the differences…)
Finally, if you are using xml spy to view the schema do not switch to schema view as it will remove the blank namespaces rendering the schema invalid (in may be invalid anyway – I’m not 100% sure… seems ok!).
It does this (opens in schema view) by default I hear you say? Well, open the schema first in any other text editor (notepad’ll do!), then in xml spy, switch to text view, add a space somewhere using the text editor and xml spy will prompt you to reload. simple.

Advertisements

2 Comments »

  1. I think this is among the most important info for me. And i am glad reading your article. But should remark on few general things, The site style is ideal, the articles is really great : D. Good job, cheers

    Comment by Son Boteilho — March 2, 2011 @ 6:08 pm

  2. This is certainly the 4th post, of your blog I personally went through.
    Although I personally like this particular 1, “MS DotNet 2005 xml validator error Walburys
    Blog” the very best. Thank you -Guy

    Comment by Kristina — February 20, 2013 @ 9:27 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: