Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xs:any processContents="skip" and xsi:type

3 views
Skip to first unread message

tomthe...@googlemail.com

unread,
Jun 4, 2009, 7:40:26 AM6/4/09
to
If I have a schema like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

and use it to validate a document (using MSXML) like this:
<foo>
<bar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="wibble"/>
</foo>

I get the following error:
Supplied input XML is invalid
Reason: Type 'wibble' is not found in Schema.
Line number: 2
Char position: 27
Source XML: <bar xsi:type="wibble"/>
^

I think this is incorrect on MSXML's part. The
processingContents="skip" should skip validation, but it is reporting
a validation error because of the xsi:type attribute. Saxon had a
similar problem which was considered a bug:
http://markmail.org/message/qqovu5o73566m5xq#query:xs%3Aany%20xsi%3Atype+page:1+mid:tciyyib5zkcfbanw+state:results

Does anybody know of a workaround for this? I need an element that can
contain genuinely arbitrary well-formed XML - "any well formed XML as
long as it doesn't contain any xsi:type attributes" isn't good enough.

Many thanks,
Tom

Martin Honnen

unread,
Jun 4, 2009, 8:09:11 AM6/4/09
to

I have used your schema and XML instance document as posted and then
applied the following JScript program using MSXML 6:

var schemas = new ActiveXObject('Msxml2.XMLSchemaCache.6.0');
schemas.add('', 'test2009060401Xsd.xml');

var doc = new ActiveXObject('Msxml2.DOMDocument.6.0');
doc.async = false;
doc.schemas = schemas;
doc.validateOnParse = true;

if (doc.load('test2009060401.xml'))
{
WScript.Echo('valid:\r\n' + doc.xml);
}
else
{
WScript.Echo(doc.parseError.reason);
}

I don't get any such error as you say you get, unless I change the
schema to use processContents="strict".

MSXML 6 used here is 6.20.1099.0 (MSXML 6.0 SP2).
--

Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/

tomthe...@googlemail.com

unread,
Jun 4, 2009, 9:58:01 AM6/4/09
to
On Jun 4, 1:09 pm, Martin Honnen <mahotr...@yahoo.de> wrote:
>        http://msmvps.com/blogs/martin_honnen/- Hide quoted text -
>
> - Show quoted text -

You're right, it does. And thank you! That was exactly the nudge I
needed.

It's not MSXML's fault at all - it's mine. It isn't failing at the
point I thought it was. It is failing earlier on during a simple well-
formedness check that shouldn't be doing validation, but
validateOnParse has been wrongly set to true although the schemacache
is empty (that seems to work unless that xsi:type is in there). The
actual validation step using the schema succeeds even in the presence
of the xsi:type.

Thanks for your help!
Tom

0 new messages