本文整理汇总了C#中System.Xml.Schema.SchemaAttDef类的典型用法代码示例。如果您正苦于以下问题:C# SchemaAttDef类的具体用法?C# SchemaAttDef怎么用?C# SchemaAttDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SchemaAttDef类属于System.Xml.Schema命名空间,在下文中一共展示了SchemaAttDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckDefaultValue
public static void CheckDefaultValue(string value, SchemaAttDef attdef, SchemaInfo sinfo, XmlNamespaceManager nsManager, XmlNameTable NameTable, object sender, ValidationEventHandler eventhandler, string baseUri, int lineNo, int linePos)
{
try
{
XmlSchemaDatatype datatype = attdef.Datatype;
if (datatype != null)
{
if (datatype.TokenizedType != XmlTokenizedType.CDATA)
{
value = value.Trim();
}
if (value.Length != 0)
{
object pVal = datatype.ParseValue(value, NameTable, nsManager);
XmlTokenizedType tokenizedType = datatype.TokenizedType;
if (tokenizedType == XmlTokenizedType.ENTITY)
{
if (datatype.Variety == XmlSchemaDatatypeVariety.List)
{
string[] strArray = (string[]) pVal;
for (int i = 0; i < strArray.Length; i++)
{
BaseValidator.ProcessEntity(sinfo, strArray[i], sender, eventhandler, baseUri, lineNo, linePos);
}
}
else
{
BaseValidator.ProcessEntity(sinfo, (string) pVal, sender, eventhandler, baseUri, lineNo, linePos);
}
}
else if ((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(pVal))
{
XmlSchemaException ex = new XmlSchemaException("Sch_EnumerationValue", pVal.ToString(), baseUri, lineNo, linePos);
if (eventhandler == null)
{
throw ex;
}
eventhandler(sender, new ValidationEventArgs(ex));
}
attdef.DefaultValueTyped = pVal;
}
}
}
catch
{
XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString(), baseUri, lineNo, linePos);
if (eventhandler == null)
{
throw exception2;
}
eventhandler(sender, new ValidationEventArgs(exception2));
}
}
示例2: AddAttDef
// add a new SchemaAttDef to the SchemaElementDecl
internal void AddAttDef(SchemaAttDef attdef)
{
_attdefs.Add(attdef.Name, attdef);
if (attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed)
{ //Not adding RequiredFixed here
if (_defaultAttdefs == null)
{
_defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
}
_defaultAttdefs.Add(attdef);
}
}
示例3: AddAttDef
internal void AddAttDef(SchemaAttDef attdef)
{
this.attdefs.Add(attdef.Name, attdef);
if ((attdef.Presence == SchemaDeclBase.Use.Required) || (attdef.Presence == SchemaDeclBase.Use.RequiredFixed))
{
this.hasRequiredAttribute = true;
}
if ((attdef.Presence == SchemaDeclBase.Use.Default) || (attdef.Presence == SchemaDeclBase.Use.Fixed))
{
if (this.defaultAttdefs == null)
{
this.defaultAttdefs = new List<IDtdDefaultAttributeInfo>();
}
this.defaultAttdefs.Add(attdef);
}
}
示例4: CheckDefaultValue
public static void CheckDefaultValue(SchemaAttDef attdef, SchemaInfo sinfo, IValidationEventHandling eventHandling, string baseUriStr)
{
try
{
if (baseUriStr == null)
{
baseUriStr = string.Empty;
}
XmlSchemaDatatype datatype = attdef.Datatype;
if (datatype != null)
{
object defaultValueTyped = attdef.DefaultValueTyped;
XmlTokenizedType tokenizedType = datatype.TokenizedType;
if (tokenizedType == XmlTokenizedType.ENTITY)
{
if (datatype.Variety == XmlSchemaDatatypeVariety.List)
{
string[] strArray = (string[]) defaultValueTyped;
for (int i = 0; i < strArray.Length; i++)
{
BaseValidator.ProcessEntity(sinfo, strArray[i], eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
}
}
else
{
BaseValidator.ProcessEntity(sinfo, (string) defaultValueTyped, eventHandling, baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
}
}
else if (((tokenizedType == XmlTokenizedType.ENUMERATION) && !attdef.CheckEnumeration(defaultValueTyped)) && (eventHandling != null))
{
XmlSchemaException exception = new XmlSchemaException("Sch_EnumerationValue", defaultValueTyped.ToString(), baseUriStr, attdef.ValueLineNumber, attdef.ValueLinePosition);
eventHandling.SendEvent(exception, XmlSeverityType.Error);
}
}
}
catch (Exception)
{
if (eventHandling != null)
{
XmlSchemaException exception2 = new XmlSchemaException("Sch_AttributeDefaultDataType", attdef.Name.ToString());
eventHandling.SendEvent(exception2, XmlSeverityType.Error);
}
}
}
示例5: XDR_BeginAttribute
private static void XDR_BeginAttribute(XdrBuilder builder)
{
if (builder._BaseDecl._TypeName.IsEmpty)
{
builder.SendValidationEvent(SR.Sch_MissAttribute);
}
SchemaAttDef attdef = null;
XmlQualifiedName qname = builder._BaseDecl._TypeName;
string prefix = builder._BaseDecl._Prefix;
// local?
if (builder._ElementDef._AttDefList != null)
{
attdef = (SchemaAttDef)builder._ElementDef._AttDefList[qname];
}
// global?
if (attdef == null)
{
// if there is no URN in this name then the name is local to the
// schema, but the global attribute was still URN qualified, so
// we need to qualify this name now.
XmlQualifiedName gname = qname;
if (prefix.Length == 0)
gname = new XmlQualifiedName(qname.Name, builder._TargetNamespace);
SchemaAttDef ad;
if (builder._SchemaInfo.AttributeDecls.TryGetValue(gname, out ad))
{
attdef = (SchemaAttDef)ad.Clone();
attdef.Name = qname;
}
else if (prefix.Length != 0)
{
builder.SendValidationEvent(SR.Sch_UndeclaredAttribute, XmlQualifiedName.ToString(qname.Name, prefix));
}
}
if (attdef != null)
{
builder.XDR_CheckAttributeDefault(builder._BaseDecl, attdef);
}
else
{
// will process undeclared types later
attdef = new SchemaAttDef(qname, prefix);
DeclBaseInfo decl = new DeclBaseInfo();
decl._Checking = true;
decl._Attdef = attdef;
decl._TypeName = builder._BaseDecl._TypeName;
decl._ElementDecl = builder._ElementDef._ElementDecl;
decl._MinOccurs = builder._BaseDecl._MinOccurs;
decl._Default = builder._BaseDecl._Default;
// add undefined attribute types
decl._Next = builder._UndefinedAttributeTypes;
builder._UndefinedAttributeTypes = decl;
}
builder._ElementDef._ElementDecl.AddAttDef(attdef);
}
示例6: AddDefaultAttributeNonDtd
internal bool AddDefaultAttributeNonDtd(SchemaAttDef attrDef)
{
// atomize names - Xsd Validator does not need to have the same nametable
string localName = _nameTable.Add(attrDef.Name.Name);
string prefix = _nameTable.Add(attrDef.Prefix);
string ns = _nameTable.Add(attrDef.Name.Namespace);
// atomize namespace - Xsd Validator does not need to have the same nametable
if (prefix.Length == 0 && ns.Length > 0)
{
prefix = _namespaceManager.LookupPrefix(ns);
Debug.Assert(prefix != null);
if (prefix == null)
{
prefix = string.Empty;
}
}
// find out if the attribute is already there
for (int i = _index + 1; i < _index + 1 + _attrCount; i++)
{
if ((object)_nodes[i].localName == (object)localName &&
(((object)_nodes[i].prefix == (object)prefix) || ((object)_nodes[i].ns == (object)ns && ns != null)))
{
return false;
}
}
// attribute does not exist -> we need to add it
NodeData attr = AddDefaultAttributeInternal(localName, ns, prefix, attrDef.DefaultValueExpanded,
attrDef.LineNumber, attrDef.LinePosition,
attrDef.ValueLineNumber, attrDef.ValueLinePosition, attrDef.Reserved != SchemaAttDef.Reserve.None);
Debug.Assert(attr != null);
attr.schemaType = (attrDef.SchemaType == null) ? (object)attrDef.Datatype : (object)attrDef.SchemaType;
attr.typedValue = attrDef.DefaultValueTyped;
return true;
}
示例7: ValidateAttribute
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
{
if (lName == null)
{
throw new ArgumentNullException("localName");
}
if (ns == null)
{
throw new ArgumentNullException("namespaceUri");
}
ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
this.CheckStateTransition(toState, MethodNames[(int) toState]);
object typedValue = null;
this.attrValid = true;
XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown;
XmlSchemaAttribute schemaAttribute = null;
XmlSchemaSimpleType xmlType = null;
ns = this.nameTable.Add(ns);
if (Ref.Equal(ns, this.NsXmlNs))
{
return null;
}
SchemaAttDef def = null;
SchemaElementDecl elementDecl = this.context.ElementDecl;
XmlQualifiedName key = new XmlQualifiedName(lName, ns);
if (this.attPresence[key] != null)
{
this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString());
if (schemaInfo != null)
{
schemaInfo.Clear();
}
return null;
}
if (Ref.Equal(ns, this.NsXsi))
{
lName = this.nameTable.Add(lName);
if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString)))
{
this.attPresence.Add(key, SchemaAttDef.Empty);
}
else
{
this.attrValid = false;
this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString());
}
}
else
{
AttributeMatchState state2;
object obj4;
XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null;
def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2);
switch (state2)
{
case AttributeMatchState.AttributeFound:
break;
case AttributeMatchState.AnyIdAttributeFound:
if (this.wildID != null)
{
this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty);
}
else
{
this.wildID = def;
XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType;
if (!schemaType.ContainsIdAttribute(false))
{
break;
}
this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty);
}
goto Label_0409;
case AttributeMatchState.UndeclaredElementAndAttribute:
def = this.CheckIsXmlAttribute(key);
if (def != null)
{
break;
}
if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace)))
{
if (this.processContents != XmlSchemaContentProcessing.Skip)
{
this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
}
}
else
{
this.attrValid = false;
this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
}
goto Label_0409;
case AttributeMatchState.UndeclaredAttribute:
def = this.CheckIsXmlAttribute(key);
if (def != null)
{
break;
//.........这里部分代码省略.........
示例8: CheckAttributeValue
private object CheckAttributeValue(object value, SchemaAttDef attdef)
{
object typedValue = null;
SchemaDeclBase decl = attdef;
XmlSchemaDatatype datatype = attdef.Datatype;
string s = value as string;
Exception innerException = null;
if (s != null)
{
innerException = datatype.TryParseValue(s, this.nameTable, this.nsResolver, out typedValue);
if (innerException == null)
{
goto Label_0050;
}
goto Label_0078;
}
innerException = datatype.TryParseValue(value, this.nameTable, this.nsResolver, out typedValue);
if (innerException != null)
{
goto Label_0078;
}
Label_0050:
if (!decl.CheckValue(typedValue))
{
this.attrValid = false;
this.SendValidationEvent("Sch_FixedAttributeValue", attdef.Name.ToString());
}
return typedValue;
Label_0078:
this.attrValid = false;
if (s == null)
{
s = XmlSchemaDatatype.ConcatenatedToString(value);
}
this.SendValidationEvent("Sch_AttributeValueDataTypeDetailed", new string[] { attdef.Name.ToString(), s, this.GetTypeName(decl), innerException.Message }, innerException);
return null;
}
示例9: CheckDefaultAttValue
private void CheckDefaultAttValue(SchemaAttDef attDef)
{
string str = (attDef.DefaultValueRaw).Trim();
XdrValidator.CheckDefaultValue(str, attDef, _SchemaInfo, _CurNsMgr, _NameTable, null, _validationEventHandler, _reader.BaseURI, _positionInfo.LineNumber, _positionInfo.LinePosition);
}
示例10: ParseAttlistDeclAsync
private async Task ParseAttlistDeclAsync() {
if (await GetTokenAsync(true).ConfigureAwait(false) != Token.QName) {
goto UnexpectedError;
}
// element name
XmlQualifiedName elementName = GetNameQualified(true);
SchemaElementDecl elementDecl;
if (!schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl)) {
if (!schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl)) {
elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
}
}
SchemaAttDef attrDef = null;
for (; ; ) {
switch (await GetTokenAsync(false).ConfigureAwait(false)) {
case Token.QName:
XmlQualifiedName attrName = GetNameQualified(true);
attrDef = new SchemaAttDef(attrName, attrName.Namespace);
attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
attrDef.LineNumber = (int)LineNo;
attrDef.LinePosition = (int)LinePos - (curPos - tokenStartPos);
break;
case Token.GreaterThan:
#if !SILVERLIGHT
if ( v1Compat ) {
// check xml:space and xml:lang
//
if ( attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals( "xml" ) && attrDef.Name.Name == "space" ) {
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
if ( attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION ) {
Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
}
if ( validate ) {
attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
}
}
}
#endif
return;
default:
goto UnexpectedError;
}
bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);
await ParseAttlistTypeAsync(attrDef, elementDecl, attrDefAlreadyExists).ConfigureAwait(false);
await ParseAttlistDefaultAsync(attrDef, attrDefAlreadyExists).ConfigureAwait(false);
// check xml:space and xml:lang
if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml")) {
if ( attrDef.Name.Name == "space" ) {
#if !SILVERLIGHT
if ( v1Compat ) {
//
string val = attrDef.DefaultValueExpanded.Trim();
if ( val.Equals( "preserve" ) || val.Equals( "default" ) ) {
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
}
}
else {
#endif
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
if ( attrDef.TokenizedType != XmlTokenizedType.ENUMERATION ) {
Throw( Res.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition );
}
#if !SILVERLIGHT
if ( validate ) {
attrDef.CheckXmlSpace( readerAdapterWithValidation.ValidationEventHandling );
}
}
#endif
}
else if ( attrDef.Name.Name == "lang" ) {
attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
}
}
// add attribute to element decl
if (!attrDefAlreadyExists) {
elementDecl.AddAttDef(attrDef);
}
}
UnexpectedError:
OnUnexpectedError();
}
示例11: ParseAttlistDecl
private void ParseAttlistDecl()
{
if (GetToken(true) != Token.QName)
{
goto UnexpectedError;
}
// element name
XmlQualifiedName elementName = GetNameQualified(true);
SchemaElementDecl elementDecl;
if (!_schemaInfo.ElementDecls.TryGetValue(elementName, out elementDecl))
{
if (!_schemaInfo.UndeclaredElementDecls.TryGetValue(elementName, out elementDecl))
{
elementDecl = new SchemaElementDecl(elementName, elementName.Namespace);
_schemaInfo.UndeclaredElementDecls.Add(elementName, elementDecl);
}
}
SchemaAttDef attrDef = null;
for (;;)
{
switch (GetToken(false))
{
case Token.QName:
XmlQualifiedName attrName = GetNameQualified(true);
attrDef = new SchemaAttDef(attrName, attrName.Namespace);
attrDef.IsDeclaredInExternal = !ParsingInternalSubset;
attrDef.LineNumber = (int)LineNo;
attrDef.LinePosition = (int)LinePos - (_curPos - _tokenStartPos);
break;
case Token.GreaterThan:
#if !SILVERLIGHT
if (_v1Compat)
{
// check xml:space and xml:lang
// BUG BUG: For backward compatibility, we check the correct type and values of the
// xml:space attribute only on the last attribute in the list.
// See Webdata bugs #97457 and #93935.
if (attrDef != null && attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml") && attrDef.Name.Name == "space")
{
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
if (attrDef.Datatype.TokenizedType != XmlTokenizedType.ENUMERATION)
{
Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
}
if (_validate)
{
attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
}
}
}
#endif
return;
default:
goto UnexpectedError;
}
bool attrDefAlreadyExists = (elementDecl.GetAttDef(attrDef.Name) != null);
ParseAttlistType(attrDef, elementDecl, attrDefAlreadyExists);
ParseAttlistDefault(attrDef, attrDefAlreadyExists);
// check xml:space and xml:lang
if (attrDef.Prefix.Length > 0 && attrDef.Prefix.Equals("xml"))
{
if (attrDef.Name.Name == "space")
{
#if !SILVERLIGHT
if (_v1Compat)
{
// BUG BUG: For backward compatibility, we check the correct type and values of the
// xml:space attribute only on the last attribute in the list, and mark it as reserved
// only its value is correct (=prevent XmlTextReader from fhrowing on invalid value).
// See Webdata bugs #98168, #97457 and #93935.
string val = attrDef.DefaultValueExpanded.Trim();
if (val.Equals("preserve") || val.Equals("default"))
{
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
}
}
else
{
#endif
attrDef.Reserved = SchemaAttDef.Reserve.XmlSpace;
if (attrDef.TokenizedType != XmlTokenizedType.ENUMERATION)
{
Throw(SR.Xml_EnumerationRequired, string.Empty, attrDef.LineNumber, attrDef.LinePosition);
}
#if !SILVERLIGHT
if (_validate)
{
attrDef.CheckXmlSpace(_readerAdapterWithValidation.ValidationEventHandling);
}
}
#endif
}
else if (attrDef.Name.Name == "lang")
{
attrDef.Reserved = SchemaAttDef.Reserve.XmlLang;
//.........这里部分代码省略.........
示例12: ParseAttlistDefault
private void ParseAttlistDefault(SchemaAttDef attrDef, bool ignoreErrors)
{
switch (GetToken(true))
{
case Token.REQUIRED:
attrDef.Presence = SchemaDeclBase.Use.Required;
return;
case Token.IMPLIED:
attrDef.Presence = SchemaDeclBase.Use.Implied;
return;
case Token.FIXED:
attrDef.Presence = SchemaDeclBase.Use.Fixed;
if (GetToken(true) != Token.Literal)
{
goto UnexpectedError;
}
break;
case Token.Literal:
break;
default:
goto UnexpectedError;
}
#if !SILVERLIGHT
if (_validate && attrDef.Datatype.TokenizedType == XmlTokenizedType.ID && !ignoreErrors)
{
SendValidationEvent(_curPos, XmlSeverityType.Error, SR.Sch_AttListPresence, string.Empty);
}
#endif
if (attrDef.TokenizedType != XmlTokenizedType.CDATA)
{
// non-CDATA attribute type normalization - strip spaces
attrDef.DefaultValueExpanded = GetValueWithStrippedSpaces();
}
else
{
attrDef.DefaultValueExpanded = GetValue();
}
attrDef.ValueLineNumber = (int)_literalLineInfo.lineNo;
attrDef.ValueLinePosition = (int)_literalLineInfo.linePos + 1;
#if !SILVERLIGHT
DtdValidator.SetDefaultTypedValue(attrDef, _readerAdapter);
#endif
return;
UnexpectedError:
OnUnexpectedError();
}
示例13: CheckValue
private void CheckValue(
string value,
SchemaAttDef attdef
) {
try {
reader.TypedValueObject = null;
bool isAttn = attdef != null;
XmlSchemaDatatype dtype = isAttn ? attdef.Datatype : context.ElementDecl.Datatype;
if (dtype == null) {
return; // no reason to check
}
if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
value = value.Trim();
}
if (value.Length == 0) {
return; // don't need to check
}
object typedValue = dtype.ParseValue(value, NameTable, nsManager);
reader.TypedValueObject = typedValue;
// Check special types
XmlTokenizedType ttype = dtype.TokenizedType;
if (ttype == XmlTokenizedType.ENTITY || ttype == XmlTokenizedType.ID || ttype == XmlTokenizedType.IDREF) {
if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
string[] ss = (string[])typedValue;
for (int i = 0; i < ss.Length; ++i) {
ProcessTokenizedType(dtype.TokenizedType, ss[i]);
}
}
else {
ProcessTokenizedType(dtype.TokenizedType, (string)typedValue);
}
}
SchemaDeclBase decl = isAttn ? (SchemaDeclBase)attdef : (SchemaDeclBase)context.ElementDecl;
if (decl.MaxLength != uint.MaxValue) {
if(value.Length > decl.MaxLength) {
SendValidationEvent(Res.Sch_MaxLengthConstraintFailed, value);
}
}
if (decl.MinLength != uint.MaxValue) {
if(value.Length < decl.MinLength) {
SendValidationEvent(Res.Sch_MinLengthConstraintFailed, value);
}
}
if (decl.Values != null && !decl.CheckEnumeration(typedValue)) {
if (dtype.TokenizedType == XmlTokenizedType.NOTATION) {
SendValidationEvent(Res.Sch_NotationValue, typedValue.ToString());
}
else {
SendValidationEvent(Res.Sch_EnumerationValue, typedValue.ToString());
}
}
if (!decl.CheckValue(typedValue)) {
if (isAttn) {
SendValidationEvent(Res.Sch_FixedAttributeValue, attdef.Name.ToString());
}
else {
SendValidationEvent(Res.Sch_FixedElementValue, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
}
}
}
catch (XmlSchemaException) {
if (attdef != null) {
SendValidationEvent(Res.Sch_AttributeValueDataType, attdef.Name.ToString());
}
else {
SendValidationEvent(Res.Sch_ElementValueDataType, XmlSchemaValidator.QNameString(context.LocalName, context.Namespace));
}
}
}
示例14: CheckDefaultValue
public static void CheckDefaultValue(
string value,
SchemaAttDef attdef,
SchemaInfo sinfo,
XmlNamespaceManager nsManager,
XmlNameTable NameTable,
object sender,
ValidationEventHandler eventhandler,
string baseUri,
int lineNo,
int linePos
) {
try {
XmlSchemaDatatype dtype = attdef.Datatype;
if (dtype == null) {
return; // no reason to check
}
if (dtype.TokenizedType != XmlTokenizedType.CDATA) {
value = value.Trim();
}
if (value.Length == 0) {
return; // don't need to check
}
object typedValue = dtype.ParseValue(value, NameTable, nsManager);
// Check special types
XmlTokenizedType ttype = dtype.TokenizedType;
if (ttype == XmlTokenizedType.ENTITY) {
if (dtype.Variety == XmlSchemaDatatypeVariety.List) {
string[] ss = (string[])typedValue;
for (int i = 0; i < ss.Length; ++i) {
ProcessEntity(sinfo, ss[i], sender, eventhandler, baseUri, lineNo, linePos);
}
}
else {
ProcessEntity(sinfo, (string)typedValue, sender, eventhandler, baseUri, lineNo, linePos);
}
}
else if (ttype == XmlTokenizedType.ENUMERATION) {
if (!attdef.CheckEnumeration(typedValue)) {
XmlSchemaException e = new XmlSchemaException(Res.Sch_EnumerationValue, typedValue.ToString(), baseUri, lineNo, linePos);
if (eventhandler != null) {
eventhandler(sender, new ValidationEventArgs(e));
}
else {
throw e;
}
}
}
attdef.DefaultValueTyped = typedValue;
}
#if DEBUG
catch (XmlSchemaException ex) {
Debug.WriteLineIf(DiagnosticsSwitches.XmlSchema.TraceError, ex.Message);
#else
catch {
#endif
XmlSchemaException e = new XmlSchemaException(Res.Sch_AttributeDefaultDataType, attdef.Name.ToString(), baseUri, lineNo, linePos);
if (eventhandler != null) {
eventhandler(sender, new ValidationEventArgs(e));
}
else {
throw e;
}
}
}
示例15: ValidateAttribute
private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) {
if (lName == null) {
throw new ArgumentNullException("localName");
}
if (ns == null) {
throw new ArgumentNullException("namespaceUri");
}
ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
CheckStateTransition(toState, MethodNames[(int)toState]);
object typedVal = null;
attrValid = true;
XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown;
XmlSchemaAttribute localAttribute = null;
XmlSchemaSimpleType localMemberType = null;
ns = nameTable.Add(ns);
if(Ref.Equal(ns,NsXmlNs)) {
return null;
}
SchemaAttDef attributeDef = null;
SchemaElementDecl currentElementDecl = context.ElementDecl;
XmlQualifiedName attQName = new XmlQualifiedName(lName, ns);
if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate;
SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString());
if (schemaInfo != null) {
schemaInfo.Clear();
}
return null;
}
if (!Ref.Equal(ns,NsXsi)) { //
XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null;
AttributeMatchState attributeMatchState;
attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState);
switch (attributeMatchState) {
case AttributeMatchState.UndeclaredElementAndAttribute:
if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute
goto case AttributeMatchState.AttributeFound;
}
if (currentElementDecl == null
&& processContents == XmlSchemaContentProcessing.Strict
&& attQName.Namespace.Length != 0
&& compiledSchemaInfo.Contains(attQName.Namespace)
) {
attrValid = false;
SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
}
else if (processContents != XmlSchemaContentProcessing.Skip) {
SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
}
break;
case AttributeMatchState.UndeclaredAttribute:
if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
goto case AttributeMatchState.AttributeFound;
}
else {
attrValid = false;
SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
}
break;
case AttributeMatchState.ProhibitedAnyAttribute:
if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
goto case AttributeMatchState.AttributeFound;
}
else {
attrValid = false;
SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
}
break;
case AttributeMatchState.ProhibitedAttribute:
attrValid = false;
SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
break;
case AttributeMatchState.AttributeNameMismatch:
attrValid = false;
SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()});
break;
case AttributeMatchState.ValidateAttributeInvalidCall:
Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type
currentState = ValidatorState.Start;
attrValid = false;
SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty);
break;
case AttributeMatchState.AnyIdAttributeFound:
if (wildID == null) {
wildID = attributeDef;
Debug.Assert(currentElementDecl != null);
XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType;
Debug.Assert(ct != null);
if (ct.ContainsIdAttribute(false)) {
//.........这里部分代码省略.........