本文整理汇总了C#中System.Xml.Schema.XmlSchemaAttribute.Validate方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaAttribute.Validate方法的具体用法?C# XmlSchemaAttribute.Validate怎么用?C# XmlSchemaAttribute.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Schema.XmlSchemaAttribute
的用法示例。
在下文中一共展示了XmlSchemaAttribute.Validate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValidatingReader
private XmlReader GetValidatingReader( XmlReader reader, XmlSchemaSet schemas, ValidationEventHandler validationEvent, XmlSchemaType schemaType, XmlSchemaElement schemaElement, XmlSchemaAttribute schemaAttribute ) {
if (schemaAttribute != null) {
return schemaAttribute.Validate(reader, null, schemas, validationEvent);
}
else if (schemaElement != null) {
return schemaElement.Validate(reader, null, schemas, validationEvent);
}
else if (schemaType != null) {
return schemaType.Validate(reader, null, schemas, validationEvent);
}
Debug.Assert( schemas != null, "schemas != null" );
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.ConformanceLevel = ConformanceLevel.Auto;
readerSettings.ValidationType = ValidationType.Schema;
readerSettings.Schemas = schemas;
readerSettings.ValidationEventHandler += validationEvent;
return XmlReader.Create( reader, readerSettings );
}
示例2: GetValidatingReader
private XmlReader GetValidatingReader(XmlReader reader, XmlSchemaSet schemas, ValidationEventHandler validationEvent, XmlSchemaType schemaType, XmlSchemaElement schemaElement, XmlSchemaAttribute schemaAttribute)
{
if (schemaAttribute != null)
{
return schemaAttribute.Validate(reader, null, schemas, validationEvent);
}
if (schemaElement != null)
{
return schemaElement.Validate(reader, null, schemas, validationEvent);
}
if (schemaType != null)
{
return schemaType.Validate(reader, null, schemas, validationEvent);
}
XmlReaderSettings settings = new XmlReaderSettings {
ConformanceLevel = ConformanceLevel.Auto,
ValidationType = ValidationType.Schema,
Schemas = schemas
};
settings.ValidationEventHandler += validationEvent;
return XmlReader.Create(reader, settings);
}
示例3: Validate
/// <summary>
/// Schema Component:
/// QName, SimpleType, Scope, Default|Fixed, annotation
/// </summary>
internal override int Validate(ValidationEventHandler h, XmlSchema schema)
{
if(IsValidated (schema.ValidationId))
return errorCount;
// -- Attribute Declaration Schema Component --
// {name}, {target namespace} -> QualifiedName. Already Compile()d.
// {type definition} -> attributeType. From SchemaType or SchemaTypeName.
// {scope} -> ParentIsSchema | isRedefineChild.
// {value constraint} -> ValidatedFixedValue, ValidatedDefaultValue.
// {annotation}
// -- Attribute Use Schema Component --
// {required}
// {attribute declaration}
// {value constraint}
// First, fill type information for type reference
if (SchemaType != null) {
SchemaType.Validate (h, schema);
attributeType = SchemaType;
}
else if (SchemaTypeName != null && SchemaTypeName != XmlQualifiedName.Empty)
{
// If type is null, then it is missing sub components .
XmlSchemaType type = schema.FindSchemaType (SchemaTypeName);
if (type is XmlSchemaComplexType)
error(h,"An attribute can't have complexType Content");
else if (type != null) { // simple type
errorCount += type.Validate (h, schema);
attributeType = type;
}
else if (SchemaTypeName == XmlSchemaComplexType.AnyTypeName)
attributeType = XmlSchemaComplexType.AnyType;
else if (XmlSchemaUtil.IsBuiltInDatatypeName (SchemaTypeName)) {
attributeType = XmlSchemaDatatype.FromName (SchemaTypeName);
if (attributeType == null)
error (h, "Invalid xml schema namespace datatype was specified.");
}
// otherwise, it might be missing sub components.
else if (!schema.IsNamespaceAbsent (SchemaTypeName.Namespace))
error (h, "Referenced schema type " + SchemaTypeName + " was not found in the corresponding schema.");
}
// Then, fill type information for the type references for the referencing attributes
if (RefName != null && RefName != XmlQualifiedName.Empty)
{
referencedAttribute = schema.FindAttribute (RefName);
// If el is null, then it is missing sub components .
if (referencedAttribute != null)
errorCount += referencedAttribute.Validate (h, schema);
// otherwise, it might be missing sub components.
else if (!schema.IsNamespaceAbsent (RefName.Namespace))
error (h, "Referenced attribute " + RefName + " was not found in the corresponding schema.");
}
if (attributeType == null)
attributeType = XmlSchemaSimpleType.AnySimpleType;
// Validate {value constraints}
if (defaultValue != null || fixedValue != null) {
XmlSchemaDatatype datatype = attributeType as XmlSchemaDatatype;
if (datatype == null)
datatype = ((XmlSchemaSimpleType) attributeType).Datatype;
if (datatype.TokenizedType == XmlTokenizedType.QName)
error (h, "By the defection of the W3C XML Schema specification, it is impossible to supply QName default or fixed values.");
else {
try {
if (defaultValue != null) {
validatedDefaultValue = datatype.Normalize (defaultValue);
datatype.ParseValue (validatedDefaultValue, null, null);
}
} catch (Exception ex) {
// FIXME: This is not a good way to handle exception.
error (h, "The Attribute's default value is invalid with its type definition.", ex);
}
try {
if (fixedValue != null) {
validatedFixedValue = datatype.Normalize (fixedValue);
validatedFixedTypedValue = datatype.ParseValue (validatedFixedValue, null, null);
}
} catch (Exception ex) {
// FIXME: This is not a good way to handle exception.
error (h, "The Attribute's fixed value is invalid with its type definition.", ex);
}
}
}
if (Use == XmlSchemaUse.None)
validatedUse = XmlSchemaUse.Optional;
else
validatedUse = Use;
#if NET_2_0
if (attributeType != null) {
attributeSchemaType = attributeType as XmlSchemaSimpleType;
if (attributeType == XmlSchemaSimpleType.AnySimpleType)
attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType;
//.........这里部分代码省略.........