473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

XmlSchema - validation trouble - .Net problem?

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
2 9034
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: BODIN | last post by:
I have an XML document, which is actually physically stored in 2 separated files. doc1.xml and doc2.xml I NEED a WAY FOR THIS SIMPLE NEED : XML file splitted into two physical files, and use...
4
by: Robert Ludewig | last post by:
This is my XML Schema (Sitemap.xsd) : <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.htw-dresden.de/SitemapNS">...
0
by: John | last post by:
Hi, I'm creating a component to generate a schema file much like VS generates for DataSets. I'm using XmlSchema to do the job and I also am using a XmlNamespaceManager to manage namespaces. ...
2
by: Chris | last post by:
I'd like to be able to access the elements in an XSD/XmlSchema object to determine things like the datatype. Can this be done without explicitly running validation on a document? Can I...
2
by: Joey P | last post by:
Hi all, I am doing a project for university whereby i have to implement a simple database related to a frozen foods company. I am having some trouble though creating a validation rule for one...
9
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected......
4
by: Igor Koretsky | last post by:
Hi. Using VB.Net System.Xml 1.0 SchemaCollection Object I am getting an error when trying to add ‘Schema A’ to the SchemaCollection. Here are my schema files..
3
by: JMD | last post by:
A set of xsd files has been working fine for us at this site, but now it gives *intermittent* errors for someone at a different cite (who is consuming the code we are producing). Most of the time...
1
by: madhuxml82 | last post by:
Dear Forum Members, I am Trying to Generate an XML File, Change the XML File, Validating the XML File with a DTD or XMLSCHEMA and Then Upload the XML File into Different set of Tables. I got...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.