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

dotnet xml

group:

XML validation problem (substitutionGroup)


XML validation problem (substitutionGroup) Michael Skulsky
7/27/2005 11:38:40 AM
dotnet xml: Hi all,

I've got the following validation problem. There are 2 schemas and a
document:

-----------------------------------------------------------------
bar.xsd
======
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:bar="urn:bar" targetNamespace="urn:bar"
xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">

<element name="test">
<complexType>
<sequence>
<element name="qwe"/>
<element ref="bar:asd"/>
</sequence>
</complexType>
</element>

<element name="asd" abstract="true"/>
</schema>

foo.xsd
=====
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:bar="urn:bar" xmlns:foo="urn:foo"
xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:foo"
elementFormDefault="qualified" attributeFormDefault="unqualified">

<import namespace="urn:bar" schemaLocation="bar.xsd"/>

<element name="foo_asd" substitutionGroup="bar:asd"/>
</schema>


test.xml
======
<?xml version="1.0" encoding="UTF-8"?>
<test xmlns="urn:bar" xmlns:foo="urn:foo"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:foo foo.xsd urn:bar bar.xsd">

<qwe/>
<foo:foo_asd/>

</test>
-----------------------------------------------------------------

The idea is that bar:asd is declared as abstract, and is substituted with
foo:foo_asd. All this validates perfectly in XML Spy and in any version of
MSXML, but the .NET parser comlains in the following way : The element
'urn:bar:test' has invalid child element 'urn:foo:foo_asd'. Expected
'urn:bar:asd'. An error occurred at , (5, 3).

It is obvious that we can't really have bar:asd, because it is abstract.
Does anybody have a clue what might be missing?
Thanks a lot in advance for any help!

Michael

Re: XML validation problem (substitutionGroup) Priscilla Walmsley
7/28/2005 8:04:48 AM
I would try just referring to the foo schema in your xsi:schemaLocation
attribute, as in xsi:schemaLocation="urn:foo foo.xsd". Since foo.xsd
imports bar.xsd, I think this should work. Different processors handle
schemaLocation attributes differently; the XML Schema spec is flexible on
this topic.

Hope that helps,
Priscilla
------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

[quoted text, click to view]

Re: XML validation problem (substitutionGroup) Zafar Abbas
8/1/2005 3:45:41 PM
Substitution groups across namespace did not work correctly in .net
framework 1.1. This works correctly in .net framework 2.0 beta2.

[quoted text, click to view]

Re: XML validation problem (substitutionGroup) Michael Skulsky
8/2/2005 12:00:00 AM
Thanks a lot for your help, in fact I've already found that out.
Both the example below and my actual XML files using this technology
validate perfectly using XmlSchemaSet object in .NET 2.0, but there seems to
be no way to have them validated in 1.1 with XmlSchemaCollection - except
for using MSXML of course.

Thanks again everybody for your help.

Michael



[quoted text, click to view]

AddThis Social Bookmark Button