-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XmlSchema reports error on a valid XML schema regarding <xs:restriction> #51778
Comments
Tagging subscribers to this area: @buyaa-n, @krwq Issue DetailsDescriptionGot following description from my customer… "... The" System.Xml.XmlReader.Create () "method incorrectly throws an exception in certain situations with 'choice' / 'sequences' in xsds. I've attached an example with two xsd files, one xml file and some source code. Both xsd files conform to the W3C standard. Both xsd files can be used successfully with the attached xml file using the online validator. The System.Xml.XmlReader.Create () method throws an exception with "Example.1.xsd" and that shouldn't actually happen. If I remove a further element from each of the two sequences in the xsd (as in "Example.0.xsd"), then the So I've attached an example with only 66 lines of source code to understand the error. Two xsd files are used to generate an XmlReader each. I would expect it to work either way. It also works for "Example.0.xsd". However, it does not work for "Example.1.xsd". The only difference between the two xsd files is that "Example.1.xsd" has an additional can element in the defined sequences. This is the exception that shouldn't come: System.Xml.Schema.XmlSchemaValidationException: Invalid particle derivation by restriction - 'The derived sequence particle at (8, 6) is not a valid restriction of the base choice particle at (17, 4) according to Sequence: Choice - MapAndSum. ' ... " ConfigurationHappens in all versions of .NET framework and is not specific to OS, platform, or configuration. Regression?This is not a regression. Other informationThe simplest fix is to remove the check below
from the following method as it is actually bogus. In the xsd:restriction case the number of immediate child particles in the sequence or in the choice cannot be compared like this since GetMappingParticle is actually recursive. private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice)
{
decimal minOccurs, maxOccurs;
minOccurs = derivedSequence.MinOccurs * derivedSequence.Items.Count;
if (derivedSequence.MaxOccurs == decimal.MaxValue)
{
maxOccurs = decimal.MaxValue;
}
else
{
maxOccurs = derivedSequence.MaxOccurs * derivedSequence.Items.Count;
}
if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseChoice.MinOccurs, baseChoice.MaxOccurs)
|| derivdSequence.Items.Count > baseChoice.Items.Count)
{
return false;
}
for (int i = 0; i < derivedSequence.Items.Count; ++i)
{
if (GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[i], baseChoice.Items) < 0)
return false;
}
return true;
}
|
Description
Got following description from my customer…
"... The" System.Xml.XmlReader.Create () "method incorrectly throws an exception in certain situations with 'choice' / 'sequences' in xsds. I've attached an example with two xsd files, one xml file and some source code. Both xsd files conform to the W3C standard. Both xsd files can be used successfully with the attached xml file using the online validator.
The System.Xml.XmlReader.Create () method throws an exception with "Example.1.xsd" and that shouldn't actually happen. If I remove a further element from each of the two sequences in the xsd (as in "Example.0.xsd"), then the
System.Xml.XmlReader.Create () also works
So I've attached an example with only 66 lines of source code to understand the error. Two xsd files are used to generate an XmlReader each. I would expect it to work either way. It also works for "Example.0.xsd". However, it does not work for "Example.1.xsd". The only difference between the two xsd files is that "Example.1.xsd" has an additional can element in the defined sequences.
This is the exception that shouldn't come:
System.Xml.Schema.XmlSchemaValidationException: Invalid particle derivation by restriction - 'The derived sequence particle at (8, 6) is not a valid restriction of the base choice particle at (17, 4) according to Sequence: Choice - MapAndSum. ' ... "
Beispiel.zip
Configuration
Happens in all versions of .NET framework and is not specific to OS, platform, or configuration.
Regression?
This is not a regression.
Other information
The simplest fix is to remove the check below
from the following method as it is actually bogus. In the xsd:restriction case the number of immediate child particles in the sequence or in the choice cannot be compared like this since GetMappingParticle is actually recursive.
The text was updated successfully, but these errors were encountered: