You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,107 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="AutoValidator.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
internal class AutoValidator : BaseValidator {
|
||||
const string x_schema = "x-schema";
|
||||
|
||||
public AutoValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) : base(reader, schemaCollection, eventHandling) {
|
||||
schemaInfo = new SchemaInfo();
|
||||
}
|
||||
|
||||
public override bool PreserveWhitespace {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void Validate() {
|
||||
ValidationType valType = DetectValidationType();
|
||||
switch(valType) {
|
||||
case ValidationType.XDR:
|
||||
reader.Validator = new XdrValidator(this);
|
||||
reader.Validator.Validate();
|
||||
break;
|
||||
|
||||
case ValidationType.Schema:
|
||||
reader.Validator = new XsdValidator(this);
|
||||
reader.Validator.Validate();
|
||||
break;
|
||||
|
||||
case ValidationType.Auto:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void CompleteValidation() {}
|
||||
|
||||
public override object FindId(string name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ValidationType DetectValidationType() {
|
||||
//Type not yet detected : Check in Schema Collection
|
||||
if (reader.Schemas != null && reader.Schemas.Count > 0) {
|
||||
XmlSchemaCollectionEnumerator enumerator = reader.Schemas.GetEnumerator();
|
||||
while (enumerator.MoveNext()) {
|
||||
XmlSchemaCollectionNode node = enumerator.CurrentNode;
|
||||
SchemaInfo schemaInfo = node.SchemaInfo;
|
||||
if(schemaInfo.SchemaType == SchemaType.XSD)
|
||||
return ValidationType.Schema;
|
||||
else if(schemaInfo.SchemaType == SchemaType.XDR)
|
||||
return ValidationType.XDR;
|
||||
}
|
||||
}
|
||||
|
||||
if (reader.NodeType == XmlNodeType.Element) {
|
||||
SchemaType schemaType = SchemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
|
||||
if (schemaType == SchemaType.XSD) {
|
||||
return ValidationType.Schema;
|
||||
}
|
||||
else if (schemaType == SchemaType.XDR) {
|
||||
return ValidationType.XDR;
|
||||
}
|
||||
else {
|
||||
int count = reader.AttributeCount;
|
||||
for (int i = 0; i < count ; i++) {
|
||||
reader.MoveToAttribute(i);
|
||||
string objectNs = reader.NamespaceURI;
|
||||
string objectName = reader.LocalName;
|
||||
if (Ref.Equal(objectNs, SchemaNames.NsXmlNs)) {
|
||||
if(XdrBuilder.IsXdrSchema(reader.Value)) {
|
||||
reader.MoveToElement();
|
||||
return ValidationType.XDR;
|
||||
}
|
||||
}
|
||||
else if (Ref.Equal(objectNs, SchemaNames.NsXsi)) {
|
||||
reader.MoveToElement();
|
||||
return ValidationType.Schema;
|
||||
}
|
||||
else if (Ref.Equal(objectNs, SchemaNames.QnDtDt.Namespace) && Ref.Equal(objectName, SchemaNames.QnDtDt.Name)) {
|
||||
reader.SchemaTypeObject = XmlSchemaDatatype.FromXdrName(reader.Value);
|
||||
reader.MoveToElement();
|
||||
return ValidationType.XDR;
|
||||
}
|
||||
} //end of for
|
||||
if(count > 0) {
|
||||
reader.MoveToElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ValidationType.Auto;
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore 618
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="BaseProcessor.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
internal class BaseProcessor {
|
||||
XmlNameTable nameTable;
|
||||
SchemaNames schemaNames;
|
||||
ValidationEventHandler eventHandler;
|
||||
XmlSchemaCompilationSettings compilationSettings;
|
||||
int errorCount = 0;
|
||||
string NsXml;
|
||||
|
||||
public BaseProcessor(XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler)
|
||||
: this(nameTable, schemaNames, eventHandler, new XmlSchemaCompilationSettings()) {} //Use the default for XmlSchemaCollection
|
||||
|
||||
public BaseProcessor(XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler, XmlSchemaCompilationSettings compilationSettings) {
|
||||
Debug.Assert(nameTable != null);
|
||||
this.nameTable = nameTable;
|
||||
this.schemaNames = schemaNames;
|
||||
this.eventHandler = eventHandler;
|
||||
this.compilationSettings = compilationSettings;
|
||||
NsXml = nameTable.Add(XmlReservedNs.NsXml);
|
||||
}
|
||||
|
||||
protected XmlNameTable NameTable {
|
||||
get { return nameTable; }
|
||||
}
|
||||
|
||||
protected SchemaNames SchemaNames {
|
||||
get {
|
||||
if (schemaNames == null) {
|
||||
schemaNames = new SchemaNames(nameTable);
|
||||
}
|
||||
return schemaNames;
|
||||
}
|
||||
}
|
||||
|
||||
protected ValidationEventHandler EventHandler {
|
||||
get { return eventHandler; }
|
||||
}
|
||||
|
||||
protected XmlSchemaCompilationSettings CompilationSettings {
|
||||
get { return compilationSettings; }
|
||||
}
|
||||
|
||||
protected bool HasErrors {
|
||||
get { return errorCount != 0; }
|
||||
}
|
||||
|
||||
protected void AddToTable(XmlSchemaObjectTable table, XmlQualifiedName qname, XmlSchemaObject item) {
|
||||
if (qname.Name.Length == 0) {
|
||||
return;
|
||||
}
|
||||
XmlSchemaObject existingObject = (XmlSchemaObject)table[qname];
|
||||
|
||||
if (existingObject != null) {
|
||||
if (existingObject == item) {
|
||||
return;
|
||||
}
|
||||
string code = Res.Sch_DupGlobalElement;
|
||||
if (item is XmlSchemaAttributeGroup) {
|
||||
string ns = nameTable.Add(qname.Namespace);
|
||||
if (Ref.Equal(ns, NsXml)) { //Check for xml namespace
|
||||
XmlSchema schemaForXmlNS = Preprocessor.GetBuildInSchema();
|
||||
XmlSchemaObject builtInAttributeGroup = schemaForXmlNS.AttributeGroups[qname];
|
||||
if ((object)existingObject == (object)builtInAttributeGroup) {
|
||||
table.Insert(qname, item);
|
||||
return;
|
||||
}
|
||||
else if ((object)item == (object)builtInAttributeGroup) { //trying to overwrite customer's component with built-in, ignore built-in
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (IsValidAttributeGroupRedefine(existingObject, item, table)){ //check for redefines
|
||||
return;
|
||||
}
|
||||
code = Res.Sch_DupAttributeGroup;
|
||||
}
|
||||
else if (item is XmlSchemaAttribute) {
|
||||
string ns = nameTable.Add(qname.Namespace);
|
||||
if (Ref.Equal(ns, NsXml)) {
|
||||
XmlSchema schemaForXmlNS = Preprocessor.GetBuildInSchema();
|
||||
XmlSchemaObject builtInAttribute = schemaForXmlNS.Attributes[qname];
|
||||
if ((object)existingObject == (object)builtInAttribute) { //replace built-in one
|
||||
table.Insert(qname, item);
|
||||
return;
|
||||
}
|
||||
else if ((object)item == (object)builtInAttribute) { //trying to overwrite customer's component with built-in, ignore built-in
|
||||
return;
|
||||
}
|
||||
}
|
||||
code = Res.Sch_DupGlobalAttribute;
|
||||
}
|
||||
else if (item is XmlSchemaSimpleType) {
|
||||
if (IsValidTypeRedefine(existingObject, item, table)) {
|
||||
return;
|
||||
}
|
||||
code = Res.Sch_DupSimpleType;
|
||||
}
|
||||
else if (item is XmlSchemaComplexType) {
|
||||
if (IsValidTypeRedefine(existingObject, item, table)) {
|
||||
return;
|
||||
}
|
||||
code = Res.Sch_DupComplexType;
|
||||
}
|
||||
else if (item is XmlSchemaGroup) {
|
||||
if (IsValidGroupRedefine(existingObject, item, table)){ //check for redefines
|
||||
return;
|
||||
}
|
||||
code = Res.Sch_DupGroup;
|
||||
}
|
||||
else if (item is XmlSchemaNotation) {
|
||||
code = Res.Sch_DupNotation;
|
||||
}
|
||||
else if (item is XmlSchemaIdentityConstraint) {
|
||||
code = Res.Sch_DupIdentityConstraint;
|
||||
}
|
||||
else {
|
||||
Debug.Assert(item is XmlSchemaElement);
|
||||
}
|
||||
SendValidationEvent(code, qname.ToString(), item);
|
||||
}
|
||||
else {
|
||||
table.Add(qname, item);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsValidAttributeGroupRedefine(XmlSchemaObject existingObject, XmlSchemaObject item, XmlSchemaObjectTable table) {
|
||||
XmlSchemaAttributeGroup attGroup = item as XmlSchemaAttributeGroup;
|
||||
XmlSchemaAttributeGroup existingAttGroup = existingObject as XmlSchemaAttributeGroup;
|
||||
if (existingAttGroup == attGroup.Redefined) { //attribute group is the redefinition of existingObject
|
||||
if (existingAttGroup.AttributeUses.Count == 0) { //If the existing one is not already compiled, then replace.
|
||||
table.Insert(attGroup.QualifiedName, attGroup); //Update with redefined entry
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (existingAttGroup.Redefined == attGroup) { //Redefined type already exists in the set, original type is added after redefined type, ignore the original type
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsValidGroupRedefine(XmlSchemaObject existingObject, XmlSchemaObject item, XmlSchemaObjectTable table) {
|
||||
XmlSchemaGroup group = item as XmlSchemaGroup;
|
||||
XmlSchemaGroup existingGroup = existingObject as XmlSchemaGroup;
|
||||
if (existingGroup == group.Redefined) { //group is the redefinition of existingObject
|
||||
if (existingGroup.CanonicalParticle == null) { //If the existing one is not already compiled, then replace.
|
||||
table.Insert(group.QualifiedName, group); //Update with redefined entry
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (existingGroup.Redefined == group) { //Redefined type already exists in the set, original type is added after redefined type, ignore the original type
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsValidTypeRedefine(XmlSchemaObject existingObject, XmlSchemaObject item, XmlSchemaObjectTable table) {
|
||||
XmlSchemaType schemaType = item as XmlSchemaType;
|
||||
XmlSchemaType existingType = existingObject as XmlSchemaType;
|
||||
if (existingType == schemaType.Redefined) { //schemaType is the redefinition of existingObject
|
||||
if (existingType.ElementDecl == null) { //If the existing one is not already compiled, then replace.
|
||||
table.Insert(schemaType.QualifiedName, schemaType); //Update with redefined entry
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (existingType.Redefined == schemaType) { //Redefined type already exists in the set, original type is added after redefined type, ignore the original type
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, XmlSchemaObject source) {
|
||||
SendValidationEvent(new XmlSchemaException(code, source), XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string msg, XmlSchemaObject source) {
|
||||
SendValidationEvent(new XmlSchemaException(code, msg, source), XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string msg1, string msg2, XmlSchemaObject source) {
|
||||
SendValidationEvent(new XmlSchemaException(code, new string[] { msg1, msg2 }, source), XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string[] args, Exception innerException, XmlSchemaObject source) {
|
||||
SendValidationEvent(new XmlSchemaException(code, args, innerException, source.SourceUri, source.LineNumber, source.LinePosition, source), XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string msg1, string msg2, string sourceUri, int lineNumber, int linePosition) {
|
||||
SendValidationEvent(new XmlSchemaException(code, new string[] { msg1, msg2 }, sourceUri, lineNumber, linePosition), XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, XmlSchemaObject source, XmlSeverityType severity) {
|
||||
SendValidationEvent(new XmlSchemaException(code, source), severity);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(XmlSchemaException e) {
|
||||
SendValidationEvent(e, XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string msg, XmlSchemaObject source, XmlSeverityType severity) {
|
||||
SendValidationEvent(new XmlSchemaException(code, msg, source), severity);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) {
|
||||
if (severity == XmlSeverityType.Error) {
|
||||
errorCount ++;
|
||||
}
|
||||
if (eventHandler != null) {
|
||||
eventHandler(null, new ValidationEventArgs(e, severity));
|
||||
}
|
||||
else if (severity == XmlSeverityType.Error) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SendValidationEventNoThrow(XmlSchemaException e, XmlSeverityType severity) {
|
||||
if (severity == XmlSeverityType.Error) {
|
||||
errorCount ++;
|
||||
}
|
||||
if (eventHandler != null) {
|
||||
eventHandler(null, new ValidationEventArgs(e, severity));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace System.Xml
|
||||
@@ -0,0 +1,304 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="BaseValidator.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
|
||||
#pragma warning disable 618
|
||||
|
||||
internal class BaseValidator {
|
||||
XmlSchemaCollection schemaCollection;
|
||||
IValidationEventHandling eventHandling;
|
||||
XmlNameTable nameTable;
|
||||
SchemaNames schemaNames;
|
||||
PositionInfo positionInfo;
|
||||
XmlResolver xmlResolver;
|
||||
Uri baseUri;
|
||||
|
||||
protected SchemaInfo schemaInfo;
|
||||
protected XmlValidatingReaderImpl reader;
|
||||
protected XmlQualifiedName elementName;
|
||||
protected ValidationState context;
|
||||
protected StringBuilder textValue;
|
||||
protected string textString;
|
||||
protected bool hasSibling;
|
||||
protected bool checkDatatype;
|
||||
|
||||
public BaseValidator(BaseValidator other) {
|
||||
reader = other.reader;
|
||||
schemaCollection = other.schemaCollection;
|
||||
eventHandling = other.eventHandling;
|
||||
nameTable = other.nameTable;
|
||||
schemaNames = other.schemaNames;
|
||||
positionInfo = other.positionInfo;
|
||||
xmlResolver = other.xmlResolver;
|
||||
baseUri = other.baseUri;
|
||||
elementName = other.elementName;
|
||||
}
|
||||
|
||||
public BaseValidator(XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling) {
|
||||
Debug.Assert(schemaCollection == null || schemaCollection.NameTable == reader.NameTable);
|
||||
this.reader = reader;
|
||||
this.schemaCollection = schemaCollection;
|
||||
this.eventHandling = eventHandling;
|
||||
nameTable = reader.NameTable;
|
||||
positionInfo = PositionInfo.GetPositionInfo(reader);
|
||||
elementName = new XmlQualifiedName();
|
||||
}
|
||||
|
||||
public XmlValidatingReaderImpl Reader {
|
||||
get { return reader; }
|
||||
}
|
||||
|
||||
public XmlSchemaCollection SchemaCollection {
|
||||
get { return schemaCollection; }
|
||||
}
|
||||
|
||||
public XmlNameTable NameTable {
|
||||
get { return nameTable; }
|
||||
}
|
||||
|
||||
public SchemaNames SchemaNames {
|
||||
get {
|
||||
if (schemaNames != null) {
|
||||
return schemaNames;
|
||||
}
|
||||
if (schemaCollection != null) {
|
||||
schemaNames = schemaCollection.GetSchemaNames(nameTable);
|
||||
}
|
||||
else {
|
||||
schemaNames = new SchemaNames(nameTable);
|
||||
}
|
||||
return schemaNames;
|
||||
}
|
||||
}
|
||||
|
||||
public PositionInfo PositionInfo {
|
||||
get { return positionInfo; }
|
||||
}
|
||||
|
||||
public XmlResolver XmlResolver {
|
||||
get { return xmlResolver; }
|
||||
set { xmlResolver = value; }
|
||||
}
|
||||
|
||||
public Uri BaseUri {
|
||||
get { return baseUri; }
|
||||
set { baseUri = value; }
|
||||
}
|
||||
|
||||
public ValidationEventHandler EventHandler {
|
||||
get { return (ValidationEventHandler)eventHandling.EventHandler; }
|
||||
}
|
||||
|
||||
public SchemaInfo SchemaInfo {
|
||||
get {
|
||||
return schemaInfo;
|
||||
}
|
||||
set {
|
||||
schemaInfo = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IDtdInfo DtdInfo {
|
||||
get {
|
||||
return schemaInfo;
|
||||
}
|
||||
set {
|
||||
SchemaInfo tmpSchemaInfo = value as SchemaInfo;
|
||||
if (tmpSchemaInfo == null) {
|
||||
throw new XmlException(Res.Xml_InternalError, string.Empty);
|
||||
}
|
||||
this.schemaInfo = tmpSchemaInfo;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool PreserveWhitespace {
|
||||
get {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Validate() {
|
||||
}
|
||||
|
||||
public virtual void CompleteValidation() {
|
||||
}
|
||||
|
||||
public virtual object FindId(string name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void ValidateText() {
|
||||
if (context.NeedValidateChildren) {
|
||||
if (context.IsNill) {
|
||||
SendValidationEvent(Res.Sch_ContentInNill, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
|
||||
return;
|
||||
}
|
||||
ContentValidator contentValidator = context.ElementDecl.ContentValidator;
|
||||
XmlSchemaContentType contentType = contentValidator.ContentType;
|
||||
if (contentType == XmlSchemaContentType.ElementOnly) {
|
||||
ArrayList names = contentValidator.ExpectedElements(context, false);
|
||||
if (names == null) {
|
||||
SendValidationEvent(Res.Sch_InvalidTextInElement, XmlSchemaValidator.BuildElementName(context.LocalName, context.Namespace));
|
||||
}
|
||||
else {
|
||||
Debug.Assert(names.Count > 0);
|
||||
SendValidationEvent(Res.Sch_InvalidTextInElementExpecting, new string[] { XmlSchemaValidator.BuildElementName(context.LocalName, context.Namespace), XmlSchemaValidator.PrintExpectedElements(names, false) });
|
||||
}
|
||||
}
|
||||
else if (contentType == XmlSchemaContentType.Empty) {
|
||||
SendValidationEvent(Res.Sch_InvalidTextInEmpty, string.Empty);
|
||||
}
|
||||
if (checkDatatype) {
|
||||
SaveTextValue(reader.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ValidateWhitespace() {
|
||||
if (context.NeedValidateChildren) {
|
||||
XmlSchemaContentType contentType = context.ElementDecl.ContentValidator.ContentType;
|
||||
if (context.IsNill) {
|
||||
SendValidationEvent(Res.Sch_ContentInNill, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
|
||||
}
|
||||
if (contentType == XmlSchemaContentType.Empty) {
|
||||
SendValidationEvent(Res.Sch_InvalidWhitespaceInEmpty, string.Empty);
|
||||
}
|
||||
if (checkDatatype) {
|
||||
SaveTextValue(reader.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveTextValue(string value) {
|
||||
if (textString.Length == 0) {
|
||||
textString = value;
|
||||
}
|
||||
else {
|
||||
if (!hasSibling) {
|
||||
textValue.Append(textString);
|
||||
hasSibling = true;
|
||||
}
|
||||
textValue.Append(value);
|
||||
}
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code) {
|
||||
SendValidationEvent(code, string.Empty);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string[] args) {
|
||||
SendValidationEvent(new XmlSchemaException(code, args, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition));
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string arg) {
|
||||
SendValidationEvent(new XmlSchemaException(code, arg, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition));
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string arg1, string arg2) {
|
||||
SendValidationEvent(new XmlSchemaException(code, new string[] { arg1, arg2 }, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition));
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(XmlSchemaException e) {
|
||||
SendValidationEvent(e, XmlSeverityType.Error);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string msg, XmlSeverityType severity) {
|
||||
SendValidationEvent(new XmlSchemaException(code, msg, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition), severity);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(string code, string[] args, XmlSeverityType severity) {
|
||||
SendValidationEvent(new XmlSchemaException(code, args, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition), severity);
|
||||
}
|
||||
|
||||
protected void SendValidationEvent(XmlSchemaException e, XmlSeverityType severity) {
|
||||
if (eventHandling != null) {
|
||||
eventHandling.SendEvent(e, severity);
|
||||
}
|
||||
else if (severity == XmlSeverityType.Error) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected static void ProcessEntity(SchemaInfo sinfo, string name, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNumber, int linePosition) {
|
||||
SchemaEntity en;
|
||||
XmlSchemaException e = null;
|
||||
if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
|
||||
// validation error, see xml spec [68]
|
||||
e = new XmlSchemaException(Res.Sch_UndeclaredEntity, name, baseUri, lineNumber, linePosition);
|
||||
}
|
||||
else if (en.NData.IsEmpty) {
|
||||
e = new XmlSchemaException(Res.Sch_UnparsedEntityRef, name, baseUri, lineNumber, linePosition);
|
||||
}
|
||||
if (e != null) {
|
||||
if (eventhandler != null) {
|
||||
eventhandler(sender, new ValidationEventArgs(e));
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static void ProcessEntity(SchemaInfo sinfo, string name, IValidationEventHandling eventHandling, string baseUriStr, int lineNumber, int linePosition) {
|
||||
SchemaEntity en;
|
||||
string errorResId = null;
|
||||
if (!sinfo.GeneralEntities.TryGetValue(new XmlQualifiedName(name), out en)) {
|
||||
// validation error, see xml spec [68]
|
||||
errorResId = Res.Sch_UndeclaredEntity;
|
||||
|
||||
}
|
||||
else if (en.NData.IsEmpty) {
|
||||
errorResId = Res.Sch_UnparsedEntityRef;
|
||||
}
|
||||
if (errorResId != null) {
|
||||
XmlSchemaException e = new XmlSchemaException(errorResId, name, baseUriStr, lineNumber, linePosition);
|
||||
|
||||
if (eventHandling != null) {
|
||||
eventHandling.SendEvent(e, XmlSeverityType.Error);
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BaseValidator CreateInstance(ValidationType valType, XmlValidatingReaderImpl reader, XmlSchemaCollection schemaCollection, IValidationEventHandling eventHandling, bool processIdentityConstraints) {
|
||||
switch(valType) {
|
||||
case ValidationType.XDR:
|
||||
return new XdrValidator(reader, schemaCollection, eventHandling);
|
||||
|
||||
case ValidationType.Schema:
|
||||
return new XsdValidator(reader, schemaCollection, eventHandling);
|
||||
|
||||
case ValidationType.DTD:
|
||||
return new DtdValidator(reader, eventHandling, processIdentityConstraints);
|
||||
|
||||
case ValidationType.Auto:
|
||||
return new AutoValidator(reader, schemaCollection, eventHandling);
|
||||
|
||||
case ValidationType.None:
|
||||
return new BaseValidator(reader, schemaCollection, eventHandling);
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
#pragma warning restore 618
|
||||
|
||||
}
|
||||
|
||||
|
||||
224
mcs/class/referencesource/System.Xml/System/Xml/Schema/BitSet.cs
Normal file
224
mcs/class/referencesource/System.Xml/System/Xml/Schema/BitSet.cs
Normal file
@@ -0,0 +1,224 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="BitSet.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
internal sealed class BitSet {
|
||||
private const int bitSlotShift = 5;
|
||||
private const int bitSlotMask = (1 << bitSlotShift) - 1;
|
||||
|
||||
private int count;
|
||||
private uint[] bits;
|
||||
|
||||
private BitSet() {
|
||||
}
|
||||
|
||||
public BitSet(int count) {
|
||||
this.count = count;
|
||||
bits = new uint[Subscript(count + bitSlotMask)];
|
||||
}
|
||||
|
||||
public int Count {
|
||||
get { return count; }
|
||||
}
|
||||
|
||||
public bool this[int index] {
|
||||
get {
|
||||
return Get(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
int bitsLength = bits.Length;
|
||||
for (int i = bitsLength; i-- > 0 ;) {
|
||||
bits[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear(int index) {
|
||||
int nBitSlot = Subscript(index);
|
||||
EnsureLength(nBitSlot + 1);
|
||||
bits[nBitSlot] &= ~((uint)1 << (index & bitSlotMask));
|
||||
}
|
||||
|
||||
public void Set(int index) {
|
||||
int nBitSlot = Subscript(index);
|
||||
EnsureLength(nBitSlot + 1);
|
||||
bits[nBitSlot] |= (uint)1 << (index & bitSlotMask);
|
||||
}
|
||||
|
||||
|
||||
public bool Get(int index) {
|
||||
bool fResult = false;
|
||||
if (index < count) {
|
||||
int nBitSlot = Subscript(index);
|
||||
fResult = ((bits[nBitSlot] & (1 << (index & bitSlotMask))) != 0);
|
||||
}
|
||||
return fResult;
|
||||
}
|
||||
|
||||
public int NextSet(int startFrom) {
|
||||
Debug.Assert(startFrom >= -1 && startFrom <= count);
|
||||
int offset = startFrom + 1;
|
||||
if (offset == count) {
|
||||
return -1;
|
||||
}
|
||||
int nBitSlot = Subscript(offset);
|
||||
offset &= bitSlotMask;
|
||||
uint word = bits[nBitSlot] >> offset;
|
||||
// locate non-empty slot
|
||||
while (word == 0) {
|
||||
if ((++ nBitSlot) == bits.Length ) {
|
||||
return -1;
|
||||
}
|
||||
offset = 0;
|
||||
word = bits[nBitSlot];
|
||||
}
|
||||
while ((word & (uint)1) == 0) {
|
||||
word >>= 1;
|
||||
offset ++;
|
||||
}
|
||||
return (nBitSlot << bitSlotShift) + offset;
|
||||
}
|
||||
|
||||
public void And(BitSet other) {
|
||||
/*
|
||||
* Need to synchronize both this and other->
|
||||
* This might lead to deadlock if one thread grabs them in one order
|
||||
* while another thread grabs them the other order.
|
||||
* Use a trick from Doug Lea's book on concurrency,
|
||||
* somewhat complicated because BitSet overrides hashCode().
|
||||
*/
|
||||
if (this == other) {
|
||||
return;
|
||||
}
|
||||
int bitsLength = bits.Length;
|
||||
int setLength = other.bits.Length;
|
||||
int n = (bitsLength > setLength) ? setLength : bitsLength;
|
||||
for (int i = n ; i-- > 0 ;) {
|
||||
bits[i] &= other.bits[i];
|
||||
}
|
||||
for (; n < bitsLength ; n++) {
|
||||
bits[n] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Or(BitSet other) {
|
||||
if (this == other) {
|
||||
return;
|
||||
}
|
||||
int setLength = other.bits.Length;
|
||||
EnsureLength(setLength);
|
||||
for (int i = setLength; i-- > 0 ;) {
|
||||
bits[i] |= other.bits[i];
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
int h = 1234;
|
||||
for (int i = bits.Length; --i >= 0;) {
|
||||
h ^= (int)bits[i] * (i + 1);
|
||||
}
|
||||
return(int)((h >> 32) ^ h);
|
||||
}
|
||||
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
// assume the same type
|
||||
if (obj != null) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
BitSet other = (BitSet) obj;
|
||||
|
||||
int bitsLength = bits.Length;
|
||||
int setLength = other.bits.Length;
|
||||
int n = (bitsLength > setLength) ? setLength : bitsLength;
|
||||
for (int i = n ; i-- > 0 ;) {
|
||||
if (bits[i] != other.bits[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (bitsLength > n) {
|
||||
for (int i = bitsLength ; i-- > n ;) {
|
||||
if (bits[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = setLength ; i-- > n ;) {
|
||||
if (other.bits[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public BitSet Clone() {
|
||||
BitSet newset = new BitSet();
|
||||
newset.count = count;
|
||||
newset.bits = (uint[])bits.Clone();
|
||||
return newset;
|
||||
}
|
||||
|
||||
|
||||
public bool IsEmpty {
|
||||
get {
|
||||
uint k = 0;
|
||||
for (int i = 0; i < bits.Length; i++) {
|
||||
k |= bits[i];
|
||||
}
|
||||
return k == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Intersects(BitSet other) {
|
||||
int i = Math.Min(this.bits.Length, other.bits.Length);
|
||||
while (--i >= 0) {
|
||||
if ((this.bits[i] & other.bits[i]) != 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int Subscript(int bitIndex) {
|
||||
return bitIndex >> bitSlotShift;
|
||||
}
|
||||
|
||||
private void EnsureLength(int nRequiredLength) {
|
||||
/* Doesn't need to be synchronized because it's an internal method. */
|
||||
if (nRequiredLength > bits.Length) {
|
||||
/* Ask for larger of doubled size or required size */
|
||||
int request = 2 * bits.Length;
|
||||
if (request < nRequiredLength)
|
||||
request = nRequiredLength;
|
||||
uint[] newBits = new uint[request];
|
||||
Array.Copy(bits, newBits, bits.Length);
|
||||
bits = newBits;
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
public void Dump(StringBuilder bb) {
|
||||
for (int i = 0; i < count; i ++) {
|
||||
bb.Append( Get(i) ? "1" : "0");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="XmlSchemaExternal.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
// Case insensitive file name key for use in a hashtable.
|
||||
|
||||
internal class ChameleonKey {
|
||||
internal string targetNS;
|
||||
internal Uri chameleonLocation;
|
||||
// Original schema (used for reference equality only)
|
||||
// stored only when the chameleonLocation is an empty URI in which case the location
|
||||
// is not a good enough identification of the schema
|
||||
internal XmlSchema originalSchema;
|
||||
int hashCode;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new chameleon key - an identification for a chameleon schema instance
|
||||
/// </summary>
|
||||
/// <param name="ns">The target namespace of the instance of the chameleon schema</param>
|
||||
/// <param name="originalSchema">The original (chameleon) schema (the one without the target namespace).
|
||||
/// This is used to get the location (base uri) and to identify the schema.</param>
|
||||
public ChameleonKey(string ns, XmlSchema originalSchema) {
|
||||
targetNS = ns;
|
||||
chameleonLocation = originalSchema.BaseUri;
|
||||
if (chameleonLocation.OriginalString.Length == 0) {
|
||||
// Only store the original schema when the location is empty URI
|
||||
// by doing this we effectively allow multiple chameleon schemas for the same target namespace
|
||||
// and URI, but that only makes sense for empty URI (not specified)
|
||||
this.originalSchema = originalSchema;
|
||||
}
|
||||
}
|
||||
|
||||
public override int GetHashCode() {
|
||||
if (hashCode == 0) {
|
||||
hashCode = targetNS.GetHashCode() + chameleonLocation.GetHashCode() +
|
||||
(originalSchema == null ? 0 : originalSchema.GetHashCode());
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj) {
|
||||
if (Ref.ReferenceEquals(this,obj)) {
|
||||
return true;
|
||||
}
|
||||
ChameleonKey cKey = obj as ChameleonKey;
|
||||
if (cKey != null) {
|
||||
// We want to compare the target NS and the schema location.
|
||||
// If the location is empty (but only then) we also want to compare the original schema instance.
|
||||
// As noted above the originalSchema is null if the chameleonLocation is non-empty. As a result we
|
||||
// can simply compare the reference to the original schema always (regardless of the schemalocation).
|
||||
Debug.Assert((chameleonLocation.OriginalString.Length == 0 && originalSchema != null)
|
||||
|| (chameleonLocation.OriginalString.Length != 0 && originalSchema == null));
|
||||
return this.targetNS.Equals(cKey.targetNS) && this.chameleonLocation.Equals(cKey.chameleonLocation) &&
|
||||
Ref.ReferenceEquals(originalSchema, cKey.originalSchema);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="CompiledIdentityConstraint.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Xml.XPath;
|
||||
using MS.Internal.Xml.XPath;
|
||||
|
||||
internal class CompiledIdentityConstraint {
|
||||
internal XmlQualifiedName name = XmlQualifiedName.Empty;
|
||||
private ConstraintRole role;
|
||||
private Asttree selector;
|
||||
private Asttree[] fields;
|
||||
internal XmlQualifiedName refer = XmlQualifiedName.Empty;
|
||||
|
||||
public enum ConstraintRole {
|
||||
Unique,
|
||||
Key,
|
||||
Keyref
|
||||
}
|
||||
|
||||
public ConstraintRole Role {
|
||||
get { return this.role; }
|
||||
}
|
||||
|
||||
public Asttree Selector {
|
||||
get { return this.selector; }
|
||||
}
|
||||
|
||||
public Asttree[] Fields {
|
||||
get { return this.fields; }
|
||||
}
|
||||
|
||||
public static readonly CompiledIdentityConstraint Empty = new CompiledIdentityConstraint();
|
||||
|
||||
private CompiledIdentityConstraint() {}
|
||||
|
||||
public CompiledIdentityConstraint(XmlSchemaIdentityConstraint constraint, XmlNamespaceManager nsmgr) {
|
||||
this.name = constraint.QualifiedName;
|
||||
|
||||
//public Asttree (string xPath, bool isField, XmlNamespaceManager nsmgr)
|
||||
try {
|
||||
this.selector = new Asttree(constraint.Selector.XPath, false, nsmgr);
|
||||
}
|
||||
catch (XmlSchemaException e) {
|
||||
e.SetSource(constraint.Selector);
|
||||
throw e;
|
||||
}
|
||||
XmlSchemaObjectCollection fields = constraint.Fields;
|
||||
Debug.Assert(fields.Count > 0);
|
||||
this.fields = new Asttree[fields.Count];
|
||||
for(int idxField = 0; idxField < fields.Count; idxField ++) {
|
||||
try {
|
||||
this.fields[idxField] = new Asttree(((XmlSchemaXPath)fields[idxField]).XPath, true, nsmgr);
|
||||
}
|
||||
catch (XmlSchemaException e) {
|
||||
e.SetSource(constraint.Fields[idxField]);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
if (constraint is XmlSchemaUnique) {
|
||||
this.role = ConstraintRole.Unique;
|
||||
}
|
||||
else if (constraint is XmlSchemaKey) {
|
||||
this.role = ConstraintRole.Key;
|
||||
}
|
||||
else { // XmlSchemaKeyref
|
||||
this.role = ConstraintRole.Keyref;
|
||||
this.refer = ((XmlSchemaKeyref)constraint).Refer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,444 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="ConstraintStruct.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Diagnostics;
|
||||
using System.Xml.XPath;
|
||||
using MS.Internal.Xml.XPath;
|
||||
|
||||
internal sealed class ConstraintStruct {
|
||||
// for each constraint
|
||||
internal CompiledIdentityConstraint constraint; // pointer to constraint
|
||||
internal SelectorActiveAxis axisSelector;
|
||||
internal ArrayList axisFields; // Add tableDim * LocatedActiveAxis in a loop
|
||||
internal Hashtable qualifiedTable; // Checking confliction
|
||||
internal Hashtable keyrefTable; // several keyref tables having connections to this one is possible
|
||||
private int tableDim; // dimension of table = numbers of fields;
|
||||
|
||||
internal int TableDim {
|
||||
get { return this.tableDim; }
|
||||
}
|
||||
|
||||
internal ConstraintStruct (CompiledIdentityConstraint constraint) {
|
||||
this.constraint = constraint;
|
||||
this.tableDim = constraint.Fields.Length;
|
||||
this.axisFields = new ArrayList(); // empty fields
|
||||
this.axisSelector = new SelectorActiveAxis (constraint.Selector, this);
|
||||
if (this.constraint.Role != CompiledIdentityConstraint.ConstraintRole.Keyref) {
|
||||
this.qualifiedTable = new Hashtable();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ActiveAxis plus the location plus the state of matching in the constraint table : only for field
|
||||
internal class LocatedActiveAxis : ActiveAxis {
|
||||
private int column; // the column in the table (the field sequence)
|
||||
internal bool isMatched; // if it's matched, then fill value in the validator later
|
||||
internal KeySequence Ks; // associated with a keysequence it will fills in
|
||||
|
||||
internal int Column {
|
||||
get { return this.column; }
|
||||
}
|
||||
|
||||
internal LocatedActiveAxis (Asttree astfield, KeySequence ks, int column) : base (astfield) {
|
||||
this.Ks = ks;
|
||||
this.column = column;
|
||||
this.isMatched = false;
|
||||
}
|
||||
|
||||
internal void Reactivate(KeySequence ks) {
|
||||
Reactivate();
|
||||
this.Ks = ks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// exist for optimization purpose
|
||||
// ActiveAxis plus
|
||||
// 1. overload endelement function from parent to return result
|
||||
// 2. combine locatedactiveaxis and keysequence more closely
|
||||
// 3. enable locatedactiveaxis reusing (the most important optimization point)
|
||||
// 4. enable ks adding to hashtable right after moving out selector node (to enable 3)
|
||||
// 5. will modify locatedactiveaxis class accordingly
|
||||
// 6. taking care of updating ConstraintStruct.axisFields
|
||||
// 7. remove constraintTable from ConstraintStruct
|
||||
// 8. still need centralized locatedactiveaxis for movetoattribute purpose
|
||||
internal class SelectorActiveAxis : ActiveAxis {
|
||||
private ConstraintStruct cs; // pointer of constraintstruct, to enable 6
|
||||
private ArrayList KSs; // stack of KSStruct, will not become less
|
||||
private int KSpointer = 0; // indicate current stack top (next available element);
|
||||
|
||||
public bool EmptyStack {
|
||||
get { return KSpointer == 0; }
|
||||
}
|
||||
|
||||
public int lastDepth {
|
||||
get { return (KSpointer == 0) ? -1 : ((KSStruct) KSs[KSpointer - 1]).depth; }
|
||||
}
|
||||
|
||||
public SelectorActiveAxis(Asttree axisTree, ConstraintStruct cs) : base(axisTree) {
|
||||
this.KSs = new ArrayList();
|
||||
this.cs = cs;
|
||||
}
|
||||
|
||||
public override bool EndElement(string localname, string URN) {
|
||||
base.EndElement(localname, URN);
|
||||
if (KSpointer > 0 && this.CurrentDepth == lastDepth) {
|
||||
return true;
|
||||
// next step PopPS, and insert into hash
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// update constraintStruct.axisFields as well, if it's new LocatedActiveAxis
|
||||
public int PushKS (int errline, int errcol) {
|
||||
// new KeySequence each time
|
||||
KeySequence ks = new KeySequence(cs.TableDim, errline, errcol);
|
||||
|
||||
// needs to clear KSStruct before using
|
||||
KSStruct kss;
|
||||
if (KSpointer < KSs.Count) {
|
||||
// reuse, clear up KSs.KSpointer
|
||||
kss = (KSStruct) KSs[KSpointer];
|
||||
kss.ks = ks;
|
||||
// reactivate LocatedActiveAxis
|
||||
for (int i = 0; i < cs.TableDim; i ++) {
|
||||
kss.fields[i].Reactivate(ks); // reassociate key sequence
|
||||
}
|
||||
}
|
||||
else { // "==", new
|
||||
kss = new KSStruct(ks, cs.TableDim);
|
||||
for (int i = 0; i < cs.TableDim; i ++) {
|
||||
kss.fields[i] = new LocatedActiveAxis (cs.constraint.Fields[i], ks, i);
|
||||
cs.axisFields.Add (kss.fields[i]); // new, add to axisFields
|
||||
}
|
||||
KSs.Add(kss);
|
||||
}
|
||||
|
||||
kss.depth = this.CurrentDepth - 1;
|
||||
|
||||
return (KSpointer ++);
|
||||
}
|
||||
|
||||
public KeySequence PopKS () {
|
||||
return ((KSStruct)KSs[-- KSpointer]).ks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class KSStruct {
|
||||
public int depth; // depth of selector when it matches
|
||||
public KeySequence ks; // ks of selector when it matches and assigned -- needs to new each time
|
||||
public LocatedActiveAxis[] fields; // array of fields activeaxis when it matches and assigned
|
||||
|
||||
public KSStruct(KeySequence ks, int dim) {
|
||||
this.ks = ks;
|
||||
this.fields = new LocatedActiveAxis[dim];
|
||||
}
|
||||
}
|
||||
|
||||
internal class TypedObject {
|
||||
|
||||
private class DecimalStruct {
|
||||
bool isDecimal = false; // rare case it will be used...
|
||||
decimal[] dvalue; // to accelerate equals operation. array <-> list
|
||||
|
||||
public bool IsDecimal {
|
||||
get { return this.isDecimal; }
|
||||
set { this.isDecimal = value; }
|
||||
}
|
||||
|
||||
public decimal[] Dvalue {
|
||||
get { return this.dvalue; }
|
||||
}
|
||||
|
||||
public DecimalStruct () {
|
||||
this.dvalue = new decimal[1];
|
||||
}
|
||||
//list
|
||||
public DecimalStruct (int dim) {
|
||||
this.dvalue = new decimal[dim];
|
||||
}
|
||||
}
|
||||
|
||||
DecimalStruct dstruct = null;
|
||||
object ovalue;
|
||||
string svalue; // only for output
|
||||
XmlSchemaDatatype xsdtype;
|
||||
int dim = 1;
|
||||
bool isList = false;
|
||||
|
||||
public int Dim {
|
||||
get { return this.dim; }
|
||||
}
|
||||
|
||||
public bool IsList {
|
||||
get { return this.isList; }
|
||||
}
|
||||
|
||||
public bool IsDecimal {
|
||||
get {
|
||||
Debug.Assert (this.dstruct != null);
|
||||
return this.dstruct.IsDecimal;
|
||||
}
|
||||
}
|
||||
public decimal[] Dvalue {
|
||||
get {
|
||||
Debug.Assert (this.dstruct != null);
|
||||
return this.dstruct.Dvalue;
|
||||
}
|
||||
}
|
||||
|
||||
public object Value {
|
||||
get {return ovalue; }
|
||||
set {ovalue = value; }
|
||||
}
|
||||
|
||||
public XmlSchemaDatatype Type {
|
||||
get {return xsdtype; }
|
||||
set {xsdtype = value; }
|
||||
}
|
||||
|
||||
public TypedObject (object obj, string svalue, XmlSchemaDatatype xsdtype) {
|
||||
this.ovalue = obj;
|
||||
this.svalue = svalue;
|
||||
this.xsdtype = xsdtype;
|
||||
if (xsdtype.Variety == XmlSchemaDatatypeVariety.List ||
|
||||
xsdtype is Datatype_base64Binary ||
|
||||
xsdtype is Datatype_hexBinary) {
|
||||
this.isList = true;
|
||||
this.dim = ((Array)obj).Length;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
// only for exception
|
||||
return this.svalue;
|
||||
}
|
||||
|
||||
public void SetDecimal () {
|
||||
|
||||
if (this.dstruct != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Debug.Assert(!this.IsDecimal);
|
||||
switch(xsdtype.TypeCode) {
|
||||
case XmlTypeCode.Byte:
|
||||
case XmlTypeCode.UnsignedByte:
|
||||
case XmlTypeCode.Short:
|
||||
case XmlTypeCode.UnsignedShort:
|
||||
case XmlTypeCode.Int:
|
||||
case XmlTypeCode.UnsignedInt:
|
||||
case XmlTypeCode.Long:
|
||||
case XmlTypeCode.UnsignedLong:
|
||||
case XmlTypeCode.Decimal:
|
||||
case XmlTypeCode.Integer:
|
||||
case XmlTypeCode.PositiveInteger:
|
||||
case XmlTypeCode.NonNegativeInteger:
|
||||
case XmlTypeCode.NegativeInteger:
|
||||
case XmlTypeCode.NonPositiveInteger:
|
||||
|
||||
if (this.isList) {
|
||||
this.dstruct = new DecimalStruct(this.dim);
|
||||
for (int i = 0; i < this.dim; i ++) {
|
||||
this.dstruct.Dvalue[i] = Convert.ToDecimal (((Array) this.ovalue).GetValue(i),NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
}
|
||||
else { //not list
|
||||
this.dstruct = new DecimalStruct();
|
||||
//possibility of list of length 1.
|
||||
this.dstruct.Dvalue[0] = Convert.ToDecimal (this.ovalue, NumberFormatInfo.InvariantInfo);
|
||||
}
|
||||
this.dstruct.IsDecimal = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (this.isList) {
|
||||
this.dstruct = new DecimalStruct(this.dim);
|
||||
}
|
||||
else {
|
||||
this.dstruct = new DecimalStruct();
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private bool ListDValueEquals (TypedObject other) {
|
||||
for (int i = 0; i < this.Dim; i ++) {
|
||||
if (this.Dvalue[i] != other.Dvalue[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Equals (TypedObject other) {
|
||||
// ? one is list with one member, another is not list -- still might be equal
|
||||
if (this.Dim != other.Dim) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.Type != other.Type) {
|
||||
//Check if types are comparable
|
||||
if (! (this.Type.IsComparable(other.Type)) ) {
|
||||
return false;
|
||||
}
|
||||
other.SetDecimal(); // can't use cast and other.Type.IsEqual (value1, value2)
|
||||
this.SetDecimal();
|
||||
if (this.IsDecimal && other.IsDecimal) { //Both are decimal / derived types
|
||||
return this.ListDValueEquals(other);
|
||||
}
|
||||
}
|
||||
|
||||
// not-Decimal derivation or type equal
|
||||
if (this.IsList) {
|
||||
if (other.IsList) { //Both are lists and values are XmlAtomicValue[] or clrvalue[]. So use Datatype_List.Compare
|
||||
return this.Type.Compare(this.Value, other.Value) == 0;
|
||||
}
|
||||
else { //this is a list and other is a single value
|
||||
Array arr1 = this.Value as System.Array;
|
||||
XmlAtomicValue[] atomicValues1 = arr1 as XmlAtomicValue[];
|
||||
if (atomicValues1 != null) { // this is a list of union
|
||||
return atomicValues1.Length == 1 && atomicValues1.GetValue(0).Equals(other.Value);
|
||||
}
|
||||
else {
|
||||
return arr1.Length == 1 && arr1.GetValue(0).Equals(other.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (other.IsList) {
|
||||
Array arr2 = other.Value as System.Array;
|
||||
XmlAtomicValue[] atomicValues2 = arr2 as XmlAtomicValue[];
|
||||
if (atomicValues2 != null) { // other is a list of union
|
||||
return atomicValues2.Length == 1 && atomicValues2.GetValue(0).Equals(this.Value);
|
||||
}
|
||||
else {
|
||||
return arr2.Length == 1 && arr2.GetValue(0).Equals(this.Value);
|
||||
}
|
||||
}
|
||||
else { //Both are not lists
|
||||
return this.Value.Equals(other.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class KeySequence {
|
||||
TypedObject[] ks;
|
||||
int dim;
|
||||
int hashcode = -1;
|
||||
int posline, poscol; // for error reporting
|
||||
|
||||
internal KeySequence (int dim, int line, int col) {
|
||||
Debug.Assert(dim > 0);
|
||||
this.dim = dim;
|
||||
this.ks = new TypedObject[dim];
|
||||
this.posline = line;
|
||||
this.poscol = col;
|
||||
}
|
||||
|
||||
public int PosLine {
|
||||
get { return this.posline; }
|
||||
}
|
||||
|
||||
public int PosCol {
|
||||
get { return this.poscol; }
|
||||
}
|
||||
|
||||
public KeySequence(TypedObject[] ks) {
|
||||
this.ks = ks;
|
||||
this.dim = ks.Length;
|
||||
this.posline = this.poscol = 0;
|
||||
}
|
||||
|
||||
public object this[int index] {
|
||||
get {
|
||||
object result = ks[index];
|
||||
return result;
|
||||
}
|
||||
set {
|
||||
ks[index] = (TypedObject) value;
|
||||
}
|
||||
}
|
||||
|
||||
// return true if no null field
|
||||
internal bool IsQualified() {
|
||||
for (int i = 0; i < this.ks.Length; ++i) {
|
||||
if ((this.ks[i] == null) || (this.ks[i].Value == null)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// it's not directly suit for hashtable, because it's always calculating address
|
||||
public override int GetHashCode() {
|
||||
if (hashcode != -1) {
|
||||
return hashcode;
|
||||
}
|
||||
hashcode = 0; // indicate it's changed. even the calculated hashcode below is 0
|
||||
for (int i = 0; i < this.ks.Length; i ++) {
|
||||
// extract its primitive value to calculate hashcode
|
||||
// decimal is handled differently to enable among different CLR types
|
||||
this.ks[i].SetDecimal();
|
||||
if (this.ks[i].IsDecimal) {
|
||||
for (int j = 0 ; j < this.ks[i].Dim ; j ++) {
|
||||
hashcode += this.ks[i].Dvalue[j].GetHashCode();
|
||||
}
|
||||
}
|
||||
//
|
||||
else {
|
||||
Array arr = this.ks[i].Value as System.Array;
|
||||
if (arr != null) {
|
||||
XmlAtomicValue[] atomicValues = arr as XmlAtomicValue[];
|
||||
if (atomicValues != null) {
|
||||
for (int j = 0 ; j < atomicValues.Length ; j ++) {
|
||||
hashcode += ((XmlAtomicValue)atomicValues.GetValue(j)).TypedValue.GetHashCode();
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int j = 0 ; j < ((Array) this.ks[i].Value).Length ; j ++) {
|
||||
hashcode += ((Array) this.ks[i].Value).GetValue(j).GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //not a list
|
||||
hashcode += this.ks[i].Value.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
// considering about derived type
|
||||
public override bool Equals(object other) {
|
||||
// each key sequence member can have different type
|
||||
KeySequence keySequence = (KeySequence)other;
|
||||
for (int i = 0; i < this.ks.Length; i++) {
|
||||
if (!this.ks[i].Equals(keySequence.ks[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(this.ks[0].ToString());
|
||||
for (int i = 1; i < this.ks.Length; i++) {
|
||||
sb.Append(" ");
|
||||
sb.Append(this.ks[i].ToString());
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1 @@
|
||||
efeab36444b5f20edd3519cf2b125ebd863c85e4
|
||||
@@ -0,0 +1 @@
|
||||
a9d85fc2028cc90798288c8b2d1c704d3e39ea4b
|
||||
@@ -0,0 +1 @@
|
||||
eb3774e4c05e4c1e35ca7f63f241c34a7fa1b809
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="IXmlSchemaInfo.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">priyal</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo"]/*' />
|
||||
public interface IXmlSchemaInfo {
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.Validity"]/*' />
|
||||
XmlSchemaValidity Validity { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.IsDefault"]/*' />
|
||||
bool IsDefault { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.IsNil"]/*' />
|
||||
bool IsNil { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.MemberType"]/*' />
|
||||
XmlSchemaSimpleType MemberType { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.SchemaType"]/*' />
|
||||
XmlSchemaType SchemaType { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.SchemaElement"]/*' />
|
||||
XmlSchemaElement SchemaElement { get; }
|
||||
|
||||
/// <include file='doc\IXmlSchemaInfo.uex' path='docs/doc[@for="IXmlSchemaInfo.SchemaAttribute"]/*' />
|
||||
XmlSchemaAttribute SchemaAttribute { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
6fdbc73d6ab2655188f92de5210d78dea358f943
|
||||
@@ -0,0 +1,87 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="XmlSchemaInferenceException.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
// <owner current="false" primary="false">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema
|
||||
{
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Resources;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Permissions;
|
||||
using System.Globalization;
|
||||
|
||||
[Serializable]
|
||||
public class XmlSchemaInferenceException : XmlSchemaException
|
||||
{
|
||||
|
||||
|
||||
protected XmlSchemaInferenceException(SerializationInfo info, StreamingContext context) : base(info, context){}
|
||||
|
||||
|
||||
[SecurityPermissionAttribute(SecurityAction.LinkDemand,SerializationFormatter=true)]
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
base.GetObjectData(info, context);
|
||||
|
||||
}
|
||||
|
||||
public XmlSchemaInferenceException() : base(null)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public XmlSchemaInferenceException(String message) : base (message, ((Exception)null), 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
public XmlSchemaInferenceException(String message, Exception innerException) : base (message, innerException, 0, 0)
|
||||
{
|
||||
}
|
||||
|
||||
/// <include file='doc\XmlSchemaException.uex' path='docs/doc[@for="XmlSchemaException.XmlSchemaException3"]/*' />
|
||||
public XmlSchemaInferenceException(String message, Exception innerException, int lineNumber, int linePosition) :
|
||||
base(message, innerException, lineNumber, linePosition)
|
||||
{
|
||||
}
|
||||
|
||||
internal XmlSchemaInferenceException(string res, string[] args) : base(res, args, null, null, 0, 0, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal XmlSchemaInferenceException(string res, string arg) : base(res, new string[] { arg }, null, null, 0, 0, null)
|
||||
{
|
||||
}
|
||||
internal XmlSchemaInferenceException(string res, string arg, string sourceUri, int lineNumber, int linePosition) :
|
||||
base(res, new string[] { arg }, null, sourceUri, lineNumber, linePosition, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal XmlSchemaInferenceException(string res, string sourceUri, int lineNumber, int linePosition) :
|
||||
base(res, (string[])null, null, sourceUri, lineNumber, linePosition, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal XmlSchemaInferenceException(string res, string[] args, string sourceUri, int lineNumber, int linePosition) :
|
||||
base(res, args, null, sourceUri, lineNumber, linePosition, null)
|
||||
{
|
||||
}
|
||||
|
||||
internal XmlSchemaInferenceException(string res, int lineNumber, int linePosition) :
|
||||
base (res, null, null, null, lineNumber, linePosition, null)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace System.Xml.Schema
|
||||
|
||||
|
||||
@@ -0,0 +1,325 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="NamespaceList.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
|
||||
internal class NamespaceList {
|
||||
public enum ListType {
|
||||
Any,
|
||||
Other,
|
||||
Set
|
||||
};
|
||||
|
||||
private ListType type = ListType.Any;
|
||||
private Hashtable set = null;
|
||||
private string targetNamespace;
|
||||
|
||||
public NamespaceList() {
|
||||
}
|
||||
|
||||
public NamespaceList(string namespaces, string targetNamespace) {
|
||||
Debug.Assert(targetNamespace != null);
|
||||
this.targetNamespace = targetNamespace;
|
||||
namespaces = namespaces.Trim();
|
||||
if (namespaces == "##any" || namespaces.Length == 0) {
|
||||
type = ListType.Any;
|
||||
}
|
||||
else if (namespaces == "##other") {
|
||||
type = ListType.Other;
|
||||
}
|
||||
else {
|
||||
type = ListType.Set;
|
||||
set = new Hashtable();
|
||||
string[] splitString = XmlConvert.SplitString(namespaces);
|
||||
for (int i = 0; i < splitString.Length; ++i) {
|
||||
if (splitString[i] == "##local") {
|
||||
set[string.Empty] = string.Empty;
|
||||
}
|
||||
else if (splitString[i] == "##targetNamespace") {
|
||||
set[targetNamespace] = targetNamespace;
|
||||
}
|
||||
else {
|
||||
XmlConvert.ToUri (splitString[i]); // can throw
|
||||
set[splitString[i]] = splitString[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NamespaceList Clone() {
|
||||
NamespaceList nsl = (NamespaceList)MemberwiseClone();
|
||||
if (type == ListType.Set) {
|
||||
Debug.Assert(set != null);
|
||||
nsl.set = (Hashtable)(set.Clone());
|
||||
}
|
||||
return nsl;
|
||||
}
|
||||
|
||||
public ListType Type {
|
||||
get { return type; }
|
||||
}
|
||||
|
||||
public string Excluded {
|
||||
get { return targetNamespace; }
|
||||
}
|
||||
|
||||
public ICollection Enumerate {
|
||||
get {
|
||||
switch (type) {
|
||||
case ListType.Set:
|
||||
return set.Keys;
|
||||
case ListType.Other:
|
||||
case ListType.Any:
|
||||
default:
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool Allows(string ns) {
|
||||
switch (type) {
|
||||
case ListType.Any:
|
||||
return true;
|
||||
case ListType.Other:
|
||||
return ns != targetNamespace && ns.Length != 0;
|
||||
case ListType.Set:
|
||||
return set[ns] != null;
|
||||
}
|
||||
Debug.Assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Allows(XmlQualifiedName qname) {
|
||||
return Allows(qname.Namespace);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
switch (type) {
|
||||
case ListType.Any:
|
||||
return "##any";
|
||||
case ListType.Other:
|
||||
return "##other";
|
||||
case ListType.Set:
|
||||
StringBuilder sb = new StringBuilder();
|
||||
bool first = true;
|
||||
foreach(string s in set.Keys) {
|
||||
if (first) {
|
||||
first = false;
|
||||
}
|
||||
else {
|
||||
sb.Append(" ");
|
||||
}
|
||||
if (s == targetNamespace) {
|
||||
sb.Append("##targetNamespace");
|
||||
}
|
||||
else if (s.Length == 0) {
|
||||
sb.Append("##local");
|
||||
}
|
||||
else {
|
||||
sb.Append(s);
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
Debug.Assert(false);
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static bool IsSubset(NamespaceList sub, NamespaceList super) {
|
||||
if (super.type == ListType.Any) {
|
||||
return true;
|
||||
}
|
||||
else if (sub.type == ListType.Other && super.type == ListType.Other) {
|
||||
return super.targetNamespace == sub.targetNamespace;
|
||||
}
|
||||
else if (sub.type == ListType.Set) {
|
||||
if (super.type == ListType.Other) {
|
||||
return !sub.set.Contains(super.targetNamespace);
|
||||
}
|
||||
else {
|
||||
Debug.Assert(super.type == ListType.Set);
|
||||
foreach (string ns in sub.set.Keys) {
|
||||
if (!super.set.Contains(ns)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static NamespaceList Union(NamespaceList o1, NamespaceList o2, bool v1Compat) {
|
||||
NamespaceList nslist = null;
|
||||
Debug.Assert(o1 != o2);
|
||||
if (o1.type == ListType.Any) { //clause 2 - o1 is Any
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else if (o2.type == ListType.Any) { //clause 2 - o2 is Any
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else if (o1.type == ListType.Set && o2.type == ListType.Set) { //clause 3 , both are sets
|
||||
nslist = o1.Clone();
|
||||
foreach (string ns in o2.set.Keys) {
|
||||
nslist.set[ns] = ns;
|
||||
}
|
||||
}
|
||||
else if (o1.type == ListType.Other && o2.type == ListType.Other) { //clause 4, both are negations
|
||||
if (o1.targetNamespace == o2.targetNamespace) { //negation of same value
|
||||
nslist = o1.Clone();
|
||||
}
|
||||
else { //Not a breaking change, going from not expressible to not(absent)
|
||||
nslist = new NamespaceList("##other", string.Empty); //clause 4, negations of different values, result is not(absent)
|
||||
}
|
||||
}
|
||||
else if (o1.type == ListType.Set && o2.type == ListType.Other) {
|
||||
if (v1Compat) {
|
||||
if (o1.set.Contains(o2.targetNamespace)) {
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else { //This was not there originally in V1, added for consistency since its not breaking
|
||||
nslist = o2.Clone();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (o2.targetNamespace != string.Empty) { //clause 5, o1 is set S, o2 is not(tns)
|
||||
nslist = o1.CompareSetToOther(o2);
|
||||
}
|
||||
else if (o1.set.Contains(string.Empty)) { //clause 6.1 - set S includes absent, o2 is not(absent)
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else { //clause 6.2 - set S does not include absent, result is not(absent)
|
||||
nslist = new NamespaceList("##other", string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (o2.type == ListType.Set && o1.type == ListType.Other) {
|
||||
if (v1Compat) {
|
||||
if (o2.set.Contains(o2.targetNamespace)) {
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else {
|
||||
nslist = o1.Clone();
|
||||
}
|
||||
}
|
||||
else { //New rules
|
||||
if (o1.targetNamespace != string.Empty) { //clause 5, o1 is set S, o2 is not(tns)
|
||||
nslist = o2.CompareSetToOther(o1);
|
||||
}
|
||||
else if (o2.set.Contains(string.Empty)) { //clause 6.1 - set S includes absent, o2 is not(absent)
|
||||
nslist = new NamespaceList();
|
||||
}
|
||||
else { //clause 6.2 - set S does not include absent, result is not(absent)
|
||||
nslist = new NamespaceList("##other", string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
return nslist;
|
||||
}
|
||||
|
||||
private NamespaceList CompareSetToOther(NamespaceList other) {
|
||||
//clause 5.1
|
||||
NamespaceList nslist = null;
|
||||
if (this.set.Contains(other.targetNamespace)) { //S contains negated ns
|
||||
if (this.set.Contains(string.Empty)) { // AND S contains absent
|
||||
nslist = new NamespaceList(); //any is the result
|
||||
}
|
||||
else { //clause 5.2
|
||||
nslist = new NamespaceList("##other", string.Empty);
|
||||
}
|
||||
}
|
||||
else if (this.set.Contains(string.Empty)) { //clause 5.3 - Not expressible
|
||||
nslist = null;
|
||||
}
|
||||
else { //clause 5.4 - Set S does not contain negated ns or absent
|
||||
nslist = other.Clone();
|
||||
}
|
||||
return nslist;
|
||||
}
|
||||
|
||||
public static NamespaceList Intersection(NamespaceList o1, NamespaceList o2, bool v1Compat) {
|
||||
NamespaceList nslist = null;
|
||||
Debug.Assert(o1 != o2); //clause 1
|
||||
if (o1.type == ListType.Any) { //clause 2 - o1 is any
|
||||
nslist = o2.Clone();
|
||||
}
|
||||
else if (o2.type == ListType.Any) { //clause 2 - o2 is any
|
||||
nslist = o1.Clone();
|
||||
}
|
||||
else if (o1.type == ListType.Set && o2.type == ListType.Other) { //Clause 3 o2 is other
|
||||
nslist = o1.Clone();
|
||||
nslist.RemoveNamespace(o2.targetNamespace);
|
||||
if (!v1Compat) {
|
||||
nslist.RemoveNamespace(string.Empty); //remove ##local
|
||||
}
|
||||
}
|
||||
else if (o1.type == ListType.Other && o2.type == ListType.Set) { //Clause 3 o1 is other
|
||||
nslist = o2.Clone();
|
||||
nslist.RemoveNamespace(o1.targetNamespace);
|
||||
if (!v1Compat) {
|
||||
nslist.RemoveNamespace(string.Empty); //remove ##local
|
||||
}
|
||||
}
|
||||
else if (o1.type == ListType.Set && o2.type == ListType.Set) { //clause 4
|
||||
nslist = o1.Clone();
|
||||
nslist = new NamespaceList();
|
||||
nslist.type = ListType.Set;
|
||||
nslist.set = new Hashtable();
|
||||
foreach(string ns in o1.set.Keys) {
|
||||
if (o2.set.Contains(ns)) {
|
||||
nslist.set.Add(ns, ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (o1.type == ListType.Other && o2.type == ListType.Other) {
|
||||
if (o1.targetNamespace == o2.targetNamespace) { //negation of same namespace name
|
||||
nslist = o1.Clone();
|
||||
return nslist;
|
||||
}
|
||||
if (!v1Compat) {
|
||||
if (o1.targetNamespace == string.Empty) { // clause 6 - o1 is negation of absent
|
||||
nslist = o2.Clone();
|
||||
}
|
||||
else if (o2.targetNamespace == string.Empty) { //clause 6 - o1 is negation of absent
|
||||
nslist = o1.Clone();
|
||||
}
|
||||
}
|
||||
//if it comes here, its not expressible //clause 5
|
||||
}
|
||||
return nslist;
|
||||
}
|
||||
|
||||
private void RemoveNamespace(string tns) {
|
||||
if (this.set[tns] != null) {
|
||||
this.set.Remove(tns);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsEmpty() {
|
||||
return ((type == ListType.Set) && ((set == null) || set.Count == 0));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
internal class NamespaceListV1Compat : NamespaceList {
|
||||
public NamespaceListV1Compat(string namespaces, string targetNamespace) : base(namespaces, targetNamespace) {}
|
||||
|
||||
public override bool Allows(string ns) {
|
||||
if (this.Type == ListType.Other) {
|
||||
return ns != Excluded;
|
||||
}
|
||||
else {
|
||||
return base.Allows(ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
418
mcs/class/referencesource/System.Xml/System/Xml/Schema/Parser.cs
Normal file
418
mcs/class/referencesource/System.Xml/System/Xml/Schema/Parser.cs
Normal file
@@ -0,0 +1,418 @@
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="Parser.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
// <owner current="true" primary="true">[....]</owner>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
internal sealed partial class Parser {
|
||||
|
||||
SchemaType schemaType;
|
||||
XmlNameTable nameTable;
|
||||
SchemaNames schemaNames;
|
||||
ValidationEventHandler eventHandler;
|
||||
XmlNamespaceManager namespaceManager;
|
||||
XmlReader reader;
|
||||
PositionInfo positionInfo;
|
||||
bool isProcessNamespaces;
|
||||
int schemaXmlDepth = 0;
|
||||
int markupDepth;
|
||||
SchemaBuilder builder;
|
||||
XmlSchema schema;
|
||||
SchemaInfo xdrSchema;
|
||||
XmlResolver xmlResolver = null; //to be used only by XDRBuilder
|
||||
|
||||
//xs:Annotation perf fix
|
||||
XmlDocument dummyDocument;
|
||||
bool processMarkup;
|
||||
XmlNode parentNode;
|
||||
XmlNamespaceManager annotationNSManager;
|
||||
string xmlns;
|
||||
|
||||
//Whitespace check for text nodes
|
||||
XmlCharType xmlCharType = XmlCharType.Instance;
|
||||
|
||||
public Parser(SchemaType schemaType, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler) {
|
||||
this.schemaType = schemaType;
|
||||
this.nameTable = nameTable;
|
||||
this.schemaNames = schemaNames;
|
||||
this.eventHandler = eventHandler;
|
||||
this.xmlResolver = System.Xml.XmlConfiguration.XmlReaderSection.CreateDefaultResolver();
|
||||
processMarkup = true;
|
||||
dummyDocument = new XmlDocument();
|
||||
}
|
||||
|
||||
public SchemaType Parse(XmlReader reader, string targetNamespace) {
|
||||
StartParsing(reader, targetNamespace);
|
||||
while(ParseReaderNode() && reader.Read()) {}
|
||||
return FinishParsing();
|
||||
}
|
||||
|
||||
public void StartParsing(XmlReader reader, string targetNamespace) {
|
||||
this.reader = reader;
|
||||
positionInfo = PositionInfo.GetPositionInfo(reader);
|
||||
namespaceManager = reader.NamespaceManager;
|
||||
if (namespaceManager == null) {
|
||||
namespaceManager = new XmlNamespaceManager(nameTable);
|
||||
isProcessNamespaces = true;
|
||||
}
|
||||
else {
|
||||
isProcessNamespaces = false;
|
||||
}
|
||||
while (reader.NodeType != XmlNodeType.Element && reader.Read()) {}
|
||||
|
||||
markupDepth = int.MaxValue;
|
||||
schemaXmlDepth = reader.Depth;
|
||||
SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
|
||||
|
||||
string code;
|
||||
if (!CheckSchemaRoot(rootType, out code)) {
|
||||
throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
|
||||
}
|
||||
|
||||
if (schemaType == SchemaType.XSD) {
|
||||
schema = new XmlSchema();
|
||||
schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
|
||||
builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
|
||||
}
|
||||
else {
|
||||
Debug.Assert(schemaType == SchemaType.XDR);
|
||||
xdrSchema = new SchemaInfo();
|
||||
xdrSchema.SchemaType = SchemaType.XDR;
|
||||
builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
|
||||
((XdrBuilder)builder).XmlResolver = xmlResolver;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckSchemaRoot(SchemaType rootType, out string code) {
|
||||
code = null;
|
||||
if (schemaType == SchemaType.None) {
|
||||
schemaType = rootType;
|
||||
}
|
||||
switch (rootType) {
|
||||
case SchemaType.XSD:
|
||||
if (schemaType != SchemaType.XSD) {
|
||||
code = Res.Sch_MixSchemaTypes;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SchemaType.XDR:
|
||||
if (schemaType == SchemaType.XSD) {
|
||||
code = Res.Sch_XSDSchemaOnly;
|
||||
return false;
|
||||
}
|
||||
else if (schemaType != SchemaType.XDR) {
|
||||
code = Res.Sch_MixSchemaTypes;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case SchemaType.DTD: //Did not detect schema type that can be parsed by this parser
|
||||
case SchemaType.None:
|
||||
code = Res.Sch_SchemaRootExpected;
|
||||
if (schemaType == SchemaType.XSD) {
|
||||
code = Res.Sch_XSDSchemaRootExpected;
|
||||
}
|
||||
return false;
|
||||
|
||||
default:
|
||||
Debug.Assert(false);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public SchemaType FinishParsing() {
|
||||
return schemaType;
|
||||
}
|
||||
|
||||
public XmlSchema XmlSchema {
|
||||
get { return schema; }
|
||||
}
|
||||
|
||||
internal XmlResolver XmlResolver {
|
||||
set {
|
||||
xmlResolver = value;
|
||||
}
|
||||
}
|
||||
|
||||
public SchemaInfo XdrSchema {
|
||||
get { return xdrSchema; }
|
||||
}
|
||||
|
||||
public bool ParseReaderNode() {
|
||||
if (reader.Depth > markupDepth) {
|
||||
if (processMarkup) {
|
||||
ProcessAppInfoDocMarkup(false);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Element) {
|
||||
if (builder.ProcessElement(reader.Prefix, reader.LocalName, reader.NamespaceURI)) {
|
||||
namespaceManager.PushScope();
|
||||
if (reader.MoveToFirstAttribute()) {
|
||||
do {
|
||||
builder.ProcessAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.Value);
|
||||
if (Ref.Equal(reader.NamespaceURI, schemaNames.NsXmlNs) && isProcessNamespaces) {
|
||||
namespaceManager.AddNamespace(reader.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
|
||||
}
|
||||
}
|
||||
while (reader.MoveToNextAttribute());
|
||||
reader.MoveToElement(); // get back to the element
|
||||
}
|
||||
builder.StartChildren();
|
||||
if (reader.IsEmptyElement) {
|
||||
namespaceManager.PopScope();
|
||||
builder.EndChildren();
|
||||
if (reader.Depth == schemaXmlDepth) {
|
||||
return false; // done
|
||||
}
|
||||
}
|
||||
else if (!builder.IsContentParsed()) { //AppInfo and Documentation
|
||||
markupDepth = reader.Depth;
|
||||
processMarkup = true;
|
||||
if (annotationNSManager == null) {
|
||||
annotationNSManager = new XmlNamespaceManager(nameTable);
|
||||
xmlns = nameTable.Add("xmlns");
|
||||
}
|
||||
ProcessAppInfoDocMarkup(true);
|
||||
}
|
||||
}
|
||||
else if (!reader.IsEmptyElement) { //UnsupportedElement in that context
|
||||
markupDepth = reader.Depth;
|
||||
processMarkup = false; //Hack to not process unsupported elements
|
||||
}
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.Text) { //Check for whitespace
|
||||
if (!xmlCharType.IsOnlyWhitespace(reader.Value)) {
|
||||
builder.ProcessCData(reader.Value);
|
||||
}
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EntityReference ||
|
||||
reader.NodeType == XmlNodeType.SignificantWhitespace ||
|
||||
reader.NodeType == XmlNodeType.CDATA) {
|
||||
builder.ProcessCData(reader.Value);
|
||||
}
|
||||
else if (reader.NodeType == XmlNodeType.EndElement) {
|
||||
|
||||
if (reader.Depth == markupDepth) {
|
||||
if (processMarkup) {
|
||||
Debug.Assert(parentNode != null);
|
||||
XmlNodeList list = parentNode.ChildNodes;
|
||||
XmlNode[] markup = new XmlNode[list.Count];
|
||||
for (int i = 0; i < list.Count; i ++) {
|
||||
markup[i] = list[i];
|
||||
}
|
||||
builder.ProcessMarkup(markup);
|
||||
namespaceManager.PopScope();
|
||||
builder.EndChildren();
|
||||
}
|
||||
markupDepth = int.MaxValue;
|
||||
}
|
||||
else {
|
||||
namespaceManager.PopScope();
|
||||
builder.EndChildren();
|
||||
}
|
||||
if(reader.Depth == schemaXmlDepth) {
|
||||
return false; // done
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ProcessAppInfoDocMarkup(bool root) {
|
||||
//First time reader is positioned on AppInfo or Documentation element
|
||||
XmlNode currentNode = null;
|
||||
|
||||
switch (reader.NodeType) {
|
||||
case XmlNodeType.Element:
|
||||
annotationNSManager.PushScope();
|
||||
currentNode = LoadElementNode(root);
|
||||
// Dev10 (TFS) #479761: The following code was to address the issue of where an in-scope namespace delaration attribute
|
||||
// was not added when an element follows an empty element. This fix will result in persisting schema in a consistent form
|
||||
// although it does not change the semantic meaning of the schema.
|
||||
// Since it is as a breaking change and Dev10 needs to maintain the backward compatibility, this fix is being reverted.
|
||||
// if (reader.IsEmptyElement) {
|
||||
// annotationNSManager.PopScope();
|
||||
// }
|
||||
break;
|
||||
|
||||
case XmlNodeType.Text:
|
||||
currentNode = dummyDocument.CreateTextNode( reader.Value );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.SignificantWhitespace:
|
||||
currentNode = dummyDocument.CreateSignificantWhitespace( reader.Value );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.CDATA:
|
||||
currentNode = dummyDocument.CreateCDataSection( reader.Value );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.EntityReference:
|
||||
currentNode = dummyDocument.CreateEntityReference( reader.Name );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.Comment:
|
||||
currentNode = dummyDocument.CreateComment( reader.Value );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.ProcessingInstruction:
|
||||
currentNode = dummyDocument.CreateProcessingInstruction( reader.Name, reader.Value );
|
||||
goto default;
|
||||
|
||||
case XmlNodeType.EndEntity:
|
||||
break;
|
||||
|
||||
case XmlNodeType.Whitespace:
|
||||
break;
|
||||
|
||||
case XmlNodeType.EndElement:
|
||||
annotationNSManager.PopScope();
|
||||
parentNode = parentNode.ParentNode;
|
||||
break;
|
||||
|
||||
default: //other possible node types: Document/DocType/DocumentFrag/Entity/Notation/Xmldecl cannot appear as children of xs:appInfo or xs:doc
|
||||
Debug.Assert(currentNode != null);
|
||||
Debug.Assert(parentNode != null);
|
||||
parentNode.AppendChild(currentNode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private XmlElement LoadElementNode(bool root) {
|
||||
Debug.Assert( reader.NodeType == XmlNodeType.Element );
|
||||
|
||||
XmlReader r = reader;
|
||||
bool fEmptyElement = r.IsEmptyElement;
|
||||
|
||||
XmlElement element = dummyDocument.CreateElement( r.Prefix, r.LocalName, r.NamespaceURI );
|
||||
element.IsEmpty = fEmptyElement;
|
||||
|
||||
if (root) {
|
||||
parentNode = element;
|
||||
}
|
||||
else {
|
||||
XmlAttributeCollection attributes = element.Attributes;
|
||||
if (r.MoveToFirstAttribute()) {
|
||||
do {
|
||||
if (Ref.Equal(r.NamespaceURI, schemaNames.NsXmlNs)) { //Namespace Attribute
|
||||
annotationNSManager.AddNamespace(r.Prefix.Length == 0 ? string.Empty : reader.LocalName, reader.Value);
|
||||
}
|
||||
XmlAttribute attr = LoadAttributeNode();
|
||||
attributes.Append( attr );
|
||||
} while(r.MoveToNextAttribute());
|
||||
}
|
||||
r.MoveToElement();
|
||||
string ns = annotationNSManager.LookupNamespace(r.Prefix);
|
||||
if (ns == null) {
|
||||
XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, namespaceManager.LookupNamespace(r.Prefix));
|
||||
attributes.Append(attr);
|
||||
}
|
||||
else if (ns.Length == 0) { //string.Empty prefix is mapped to string.Empty NS by default
|
||||
string elemNS = namespaceManager.LookupNamespace(r.Prefix);
|
||||
if (elemNS != string.Empty) {
|
||||
XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, elemNS);
|
||||
attributes.Append(attr);
|
||||
}
|
||||
}
|
||||
|
||||
while (r.MoveToNextAttribute()) {
|
||||
if (r.Prefix.Length != 0) {
|
||||
string attNS = annotationNSManager.LookupNamespace(r.Prefix);
|
||||
if (attNS == null) {
|
||||
XmlAttribute attr = CreateXmlNsAttribute(r.Prefix, namespaceManager.LookupNamespace(r.Prefix));
|
||||
attributes.Append(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
r.MoveToElement();
|
||||
|
||||
parentNode.AppendChild(element);
|
||||
if (!r.IsEmptyElement) {
|
||||
parentNode = element;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
private XmlAttribute CreateXmlNsAttribute(string prefix, string value) {
|
||||
XmlAttribute attr;
|
||||
if (prefix.Length == 0) {
|
||||
attr = dummyDocument.CreateAttribute(string.Empty, xmlns, XmlReservedNs.NsXmlNs);
|
||||
}
|
||||
else {
|
||||
attr = dummyDocument.CreateAttribute(xmlns, prefix, XmlReservedNs.NsXmlNs);
|
||||
}
|
||||
attr.AppendChild(dummyDocument.CreateTextNode(value));
|
||||
annotationNSManager.AddNamespace(prefix, value);
|
||||
return attr;
|
||||
}
|
||||
|
||||
private XmlAttribute LoadAttributeNode() {
|
||||
Debug.Assert(reader.NodeType == XmlNodeType.Attribute);
|
||||
|
||||
XmlReader r = reader;
|
||||
|
||||
XmlAttribute attr = dummyDocument.CreateAttribute(r.Prefix, r.LocalName, r.NamespaceURI);
|
||||
|
||||
while (r.ReadAttributeValue() ) {
|
||||
switch (r.NodeType) {
|
||||
case XmlNodeType.Text:
|
||||
attr.AppendChild(dummyDocument.CreateTextNode(r.Value));
|
||||
continue;
|
||||
case XmlNodeType.EntityReference:
|
||||
attr.AppendChild(LoadEntityReferenceInAttribute());
|
||||
continue;
|
||||
default:
|
||||
throw XmlLoader.UnexpectedNodeType( r.NodeType );
|
||||
}
|
||||
}
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
private XmlEntityReference LoadEntityReferenceInAttribute() {
|
||||
Debug.Assert(reader.NodeType == XmlNodeType.EntityReference);
|
||||
|
||||
XmlEntityReference eref = dummyDocument.CreateEntityReference( reader.LocalName );
|
||||
if ( !reader.CanResolveEntity ) {
|
||||
return eref;
|
||||
}
|
||||
reader.ResolveEntity();
|
||||
|
||||
while (reader.ReadAttributeValue()) {
|
||||
switch (reader.NodeType) {
|
||||
case XmlNodeType.Text:
|
||||
eref.AppendChild(dummyDocument.CreateTextNode(reader.Value));
|
||||
continue;
|
||||
case XmlNodeType.EndEntity:
|
||||
if ( eref.ChildNodes.Count == 0 ) {
|
||||
eref.AppendChild(dummyDocument.CreateTextNode(String.Empty));
|
||||
}
|
||||
return eref;
|
||||
case XmlNodeType.EntityReference:
|
||||
eref.AppendChild(LoadEntityReferenceInAttribute());
|
||||
break;
|
||||
default:
|
||||
throw XmlLoader.UnexpectedNodeType( reader.NodeType );
|
||||
}
|
||||
}
|
||||
|
||||
return eref;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace System.Xml
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
namespace System.Xml.Schema {
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Threading.Tasks;
|
||||
|
||||
internal sealed partial class Parser {
|
||||
|
||||
public async Task< SchemaType > ParseAsync(XmlReader reader, string targetNamespace) {
|
||||
await StartParsingAsync(reader, targetNamespace).ConfigureAwait(false);
|
||||
while(ParseReaderNode() && await reader.ReadAsync().ConfigureAwait(false)) {}
|
||||
return FinishParsing();
|
||||
}
|
||||
|
||||
public async Task StartParsingAsync(XmlReader reader, string targetNamespace) {
|
||||
this.reader = reader;
|
||||
positionInfo = PositionInfo.GetPositionInfo(reader);
|
||||
namespaceManager = reader.NamespaceManager;
|
||||
if (namespaceManager == null) {
|
||||
namespaceManager = new XmlNamespaceManager(nameTable);
|
||||
isProcessNamespaces = true;
|
||||
}
|
||||
else {
|
||||
isProcessNamespaces = false;
|
||||
}
|
||||
while (reader.NodeType != XmlNodeType.Element && await reader.ReadAsync().ConfigureAwait(false)) {}
|
||||
|
||||
markupDepth = int.MaxValue;
|
||||
schemaXmlDepth = reader.Depth;
|
||||
SchemaType rootType = schemaNames.SchemaTypeFromRoot(reader.LocalName, reader.NamespaceURI);
|
||||
|
||||
string code;
|
||||
if (!CheckSchemaRoot(rootType, out code)) {
|
||||
throw new XmlSchemaException(code, reader.BaseURI, positionInfo.LineNumber, positionInfo.LinePosition);
|
||||
}
|
||||
|
||||
if (schemaType == SchemaType.XSD) {
|
||||
schema = new XmlSchema();
|
||||
schema.BaseUri = new Uri(reader.BaseURI, UriKind.RelativeOrAbsolute);
|
||||
builder = new XsdBuilder(reader, namespaceManager, schema, nameTable, schemaNames, eventHandler);
|
||||
}
|
||||
else {
|
||||
Debug.Assert(schemaType == SchemaType.XDR);
|
||||
xdrSchema = new SchemaInfo();
|
||||
xdrSchema.SchemaType = SchemaType.XDR;
|
||||
builder = new XdrBuilder(reader, namespaceManager, xdrSchema, targetNamespace, nameTable, schemaNames, eventHandler);
|
||||
((XdrBuilder)builder).XmlResolver = xmlResolver;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace System.Xml
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user