By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,862 Members | 1,767 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,862 IT Pros & Developers. It's quick & easy.

XmlSchema - validation trouble - .Net problem?

P: n/a
Hello,

I have error when reading schema using XmlSchema. Read and then .Compile:

System.Xml.Schema.XmlSchemaException: May not be nominated as the
{substitution
group affiliation} of any other declaration. An error occurred at , (11, 3).
Schema compile error:
System.Exception: Schema error ---> System.Xml.Schema.XmlSchemaException:
May no
t be nominated as the {substitution group affiliation} of any other
declaration.
An error occurred at , (11, 3).
--- End of inner exception stack trace ---
at XBRLMainClass.SchemaErrorHandler(Object sender, ValidationEventArgs
vea) i
n c:\...\Main.cs:line 88
at System.Xml.Schema.Compiler.SendValidationEvent(Xml SchemaException e,
XmlSe
verityType severity)
at
System.Xml.Schema.Compiler.CompileSubstitutionGrou p(XmlSchemaSubstitutionG
roup substitutionGroup)
at System.Xml.Schema.Compiler.CompileTo(SchemaInfo schemaInfo)
at System.Xml.Schema.XmlSchema.Compile(XmlSchemaColle ction collection,
XmlNam
eTable nameTable, SchemaNames schemaNames, ValidationEventHandler
validationEven
tHandler, String targetNamespace, SchemaInfo schemaInfo, Boolean
compileContentM
odel, XmlResolver resolver)
at System.Xml.Schema.XmlSchema.Compile(ValidationEven tHandler
validationEvent
Handler)

When I look at failing line I see:

<element id="pfsInc" name="Inc" type="xi:monItemType"
substitutionGroup="xi:item" />

Element item is defined as

<element name="item" type="anySimpleType" abstract="true" />

What is wrong here?

Why error message doesn't specify exacly which file at error occured?

It doesn't matter if I specify abstract="true" or remove it.

Anybody can help to find the answer? As per W3 it should work. However
doesn't.

Code I use is simple:

fn=schemaFileNameString;
FileStream fs=new FileStream(fn,FileMode.Open);

XmlSchema xsd=null;

try {

xsd=XmlSchema.Read(fs,new ValidationEventHandler(SchemaErrorHandler));

}

catch (Exception ex) {

Console.WriteLine("Schema read
exception:{0}{1}",Environment.NewLine,ex.ToString( ));

Console.WriteLine("Schema read failed.");

return;

}

finally {

fs.Close();

fs=null;

}

// compile schema

try {

xsd.Compile(new ValidationEventHandler(SchemaErrorHandler));

}

catch (Exception ex) {

Console.WriteLine("Schema compile error:{0}{1}",

Environment.NewLine,

ex.ToString());

return;

}

Test schema file

<?xml version="1.0"?>
<schema targetNamespace="instance" xmlns:xi="instance"
xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<simpleType name="monT">
<restriction base="decimal"/>
</simpleType>
<simpleType name="shaT">
<restriction base="decimal">
<minInclusive value="0"/>
</restriction>
</simpleType>
<element name="itemAbs" type="anySimpleType" />
<!-- element name="item" type="anySimpleType"
substitutionGroup="xi:itemAbs" / -->
<element name="Inc" type="xi:monT" substitutionGroup="xi:itemAbs"/>
<element name="Dec" type="xi:shaT" />
</schema>

Anybody can point me in right direction? How can I define substitution group
in a way compatible with .Net?

Thanks!
Alex
Nov 11 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
This schema is NOT valid. There are several things wrong with it such as the
fact that you reference complex types such as "xs:annotated" and "xs:facet"
which are not defined in an imported schema for the
"http://www.w3.org/2001/XMLSchema" namespace. However, even if you did do
this I would suggest not trying to define interactions between user-defined
types and types defined in the schema for Schema because the schema for
Schema isn't actually a valid schema according to the rules specified in the
W3C XML Schema recommendation.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
Further to previous.

I took example of subsitutionGroup definition from 3.3.2 at
http://www.w3.org/TR/xmlschema-1/#cElement_Declarations.

Test file I use is:

<xs:schema targetNamespace="schema" xmlns:x="schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="facet">
<xs:complexContent>
<xs:extension base="xs:annotated">
<xs:attribute name="value" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="facet" type="xs:facet" abstract="true"/>

<xs:element name="encoding" substitutionGroup="xs:facet">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:facet">
<xs:sequence>
<xs:element ref="annotation" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:encodings"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>

<xs:element name="period" substitutionGroup="xs:facet">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:facet">
<xs:sequence>
<xs:element ref="annotation" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:duration"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>

<xs:complexType name="datatype">
<xs:sequence>
<xs:element ref="facet" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NCName" use="optional"/>
</xs:complexType>

</xs:schema>

.Net ReadXMLSchema or XmlSchema.Compile fails with:
System.Xml.Schema.XmlSchemaException: Reference to undeclared substitution
group
affiliation. An error occurred at , (13, 3).
Schema compile error:
System.Exception: Schema error ---> System.Xml.Schema.XmlSchemaException:
Refere
nce to undeclared substitution group affiliation. An error occurred at ,
(13, 3)
.
--- End of inner exception stack trace ---
at XBRLMainClass.SchemaErrorHandler(Object sender, ValidationEventArgs
vea) i
n c:\...\Main.cs:line 88
at System.Xml.Schema.Compiler.SendValidationEvent(Xml SchemaException e,
XmlSe
verityType severity)
at
System.Xml.Schema.Compiler.CompileSubstitutionGrou p(XmlSchemaSubstitutionG
roup substitutionGroup)
at System.Xml.Schema.Compiler.CompileTo(SchemaInfo schemaInfo)
at System.Xml.Schema.XmlSchema.Compile(XmlSchemaColle ction collection,
XmlNam
eTable nameTable, SchemaNames schemaNames, ValidationEventHandler
validationEven
tHandler, String targetNamespace, SchemaInfo schemaInfo, Boolean
compileContentM
odel, XmlResolver resolver)
at System.Xml.Schema.XmlSchema.Compile(ValidationEven tHandler
validationEvent
Handler).

And validator at
http://apps.gotdotnet.com/xmltools/x...r/Default.aspx fails in
different way:
Reference to undeclared substitution group affiliation. An error occurred at , (13, 3).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:annotated' is used
as a base for complex type extension". An error occurred at , (5, 5).
Type 'http://www.w3.org/2001/XMLSchema:facet' is not declared. An error
occurred at , (11, 3).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet' is used as a base for complex type restriction". An error occurred at , (16, 6).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet' is used as a base for complex type restriction". An error occurred at , (29, 6).
The 'facet' element is not declared. An error occurred at , (41, 5).

What's the problem?

Is the sample in w3.org docs wrong? Who is right, .Net validator, gotdotnet validator or w3.org?

Can anybody point in right direction? Or provide a sample of xsd file with
substitution groups working with .Net validation?
PLEASE!!!!

Nov 11 '05 #2

P: n/a
Dare,

here are 2 examples of schema: first one is validated Ok, and second one
fails. I have to process original schema as in second one. I can't change it
and I did not create it. And creators insist that schema is Ok.

The difference is that second schema uses substitutionGroup. And .net
validator fails over it.
At the same time, second variant is validated Ok by
http://apps.gotdotnet.com/xmltools/xsdvalidator/.

variant which passes XmlSchema.Compile:
<schema targetNamespace="sch" xmlns:xs="sch"
xmlns="http://www.w3.org/2001/XMLSchema" >

<simpleType name="monetary">
<restriction base="decimal"/>
</simpleType>
<simpleType name="shares">
<restriction base="decimal">
<minInclusive value="0"/>
</restriction>
</simpleType>

<element name="item-abs" type="decimal" abstract="true" />

<element id="iascf-pfs_WorkProgress" name="WorkProgress"
type="xs:monetary" />
<element id="iascf-pfs_WarrantyProvisionNonCurrent"
name="WarrantyProvisionNonCurrent" type="xs:monetary" />
</schema>

Variant, which fails in XmlSchema.Compile and passes in xsdvalidator:
<schema targetNamespace="sch" xmlns:xs="sch"
xmlns="http://www.w3.org/2001/XMLSchema" >

<simpleType name="monetary">
<restriction base="decimal"/>
</simpleType>
<simpleType name="shares">
<restriction base="decimal">
<minInclusive value="0"/>
</restriction>
</simpleType>

<element name="item-abs" type="decimal" abstract="true" />

<element id="iascf-pfs_WorkProgress" name="WorkProgress"
type="xs:monetary" substitutionGroup="xs:item-abs"/>
<element id="iascf-pfs_WarrantyProvisionNonCurrent"
name="WarrantyProvisionNonCurrent" type="xs:monetary"
substitutionGroup="xs:item-abs" />
</schema>

When I check what w3.org says on subtitution groups - I don't see why second
schema should fail.

Can you explain (or point out where I can see explanation for this) why
second variant fails in XmlSchema.Compile?

To me it looks like bug in .Net. Or where?

Sorry, if my previous example was not completely Ok. I hope this one is more
clear

Btw, would you mind to explain a bit what you mean by "...because the schema
for
Schema isn't actually a valid schema according to the rules specified in the W3C XML Schema recommendation."?

Rgds
Alex

"Dare Obasanjo [MSFT]" <da***@online.microsoft.com> wrote in message
news:3f********@news.microsoft.com... This schema is NOT valid. There are several things wrong with it such as the fact that you reference complex types such as "xs:annotated" and "xs:facet" which are not defined in an imported schema for the
"http://www.w3.org/2001/XMLSchema" namespace. However, even if you did do
this I would suggest not trying to define interactions between user-defined types and types defined in the schema for Schema because the schema for
Schema isn't actually a valid schema according to the rules specified in the W3C XML Schema recommendation.

--
This posting is provided "AS IS" with no warranties, and confers no rights.

"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:O5**************@tk2msftngp13.phx.gbl...
Further to previous.

I took example of subsitutionGroup definition from 3.3.2 at
http://www.w3.org/TR/xmlschema-1/#cElement_Declarations.

Test file I use is:

<xs:schema targetNamespace="schema" xmlns:x="schema"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="facet">
<xs:complexContent>
<xs:extension base="xs:annotated">
<xs:attribute name="value" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:element name="facet" type="xs:facet" abstract="true"/>

<xs:element name="encoding" substitutionGroup="xs:facet">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:facet">
<xs:sequence>
<xs:element ref="annotation" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:encodings"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>

<xs:element name="period" substitutionGroup="xs:facet">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="xs:facet">
<xs:sequence>
<xs:element ref="annotation" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="value" type="xs:duration"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>

<xs:complexType name="datatype">
<xs:sequence>
<xs:element ref="facet" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:NCName" use="optional"/>
</xs:complexType>

</xs:schema>

.Net ReadXMLSchema or XmlSchema.Compile fails with:
System.Xml.Schema.XmlSchemaException: Reference to undeclared substitution group
affiliation. An error occurred at , (13, 3).
Schema compile error:
System.Exception: Schema error ---> System.Xml.Schema.XmlSchemaException: Refere
nce to undeclared substitution group affiliation. An error occurred at ,
(13, 3)
.
--- End of inner exception stack trace ---
at XBRLMainClass.SchemaErrorHandler(Object sender, ValidationEventArgs vea) i
n c:\...\Main.cs:line 88
at System.Xml.Schema.Compiler.SendValidationEvent(Xml SchemaException e, XmlSe
verityType severity)
at
System.Xml.Schema.Compiler.CompileSubstitutionGrou p(XmlSchemaSubstitutionG roup substitutionGroup)
at System.Xml.Schema.Compiler.CompileTo(SchemaInfo schemaInfo)
at System.Xml.Schema.XmlSchema.Compile(XmlSchemaColle ction collection, XmlNam
eTable nameTable, SchemaNames schemaNames, ValidationEventHandler
validationEven
tHandler, String targetNamespace, SchemaInfo schemaInfo, Boolean
compileContentM
odel, XmlResolver resolver)
at System.Xml.Schema.XmlSchema.Compile(ValidationEven tHandler
validationEvent
Handler).

And validator at
http://apps.gotdotnet.com/xmltools/x...r/Default.aspx fails in
different way:
Reference to undeclared substitution group affiliation. An error occurred
at
, (13, 3).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:annotated' is
used as a base for complex type extension". An error occurred at , (5, 5).
Type 'http://www.w3.org/2001/XMLSchema:facet' is not declared. An error
occurred at , (11, 3).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet' is used as a
base for complex type restriction". An error occurred at , (16, 6).
Undefined complexType 'http://www.w3.org/2001/XMLSchema:facet' is used
as a
base for complex type restriction". An error occurred at , (29, 6).
The 'facet' element is not declared. An error occurred at , (41, 5).

What's the problem?

Is the sample in w3.org docs wrong? Who is right, .Net validator,

gotdotnet
validator or w3.org?

Can anybody point in right direction? Or provide a sample of xsd file

with substitution groups working with .Net validation?
PLEASE!!!!


Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.