本文整理汇总了C#中System.Xml.Schema.XmlSchemaSimpleTypeRestriction类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaSimpleTypeRestriction类的具体用法?C# XmlSchemaSimpleTypeRestriction怎么用?C# XmlSchemaSimpleTypeRestriction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemaSimpleTypeRestriction类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaSimpleTypeRestriction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSchema
public XmlSchemaElement GetSchema()
{
var type = new XmlSchemaComplexType();
type.Attributes.Add(new XmlSchemaAttribute
{
Name = "refValue",
Use = XmlSchemaUse.Required,
SchemaTypeName =
new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema")
});
type.Attributes.Add(new XmlSchemaAttribute
{
Name = "test",
Use = XmlSchemaUse.Optional,
SchemaTypeName =
new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
});
var restriction = new XmlSchemaSimpleTypeRestriction
{
BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
};
restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "years"});
restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "weeks"});
restriction.Facets.Add(new XmlSchemaEnumerationFacet {Value = "days"});
var simpleType = new XmlSchemaSimpleType {Content = restriction};
type.Attributes.Add(new XmlSchemaAttribute
{
Name = "units",
Use = XmlSchemaUse.Required,
SchemaType = simpleType
});
type.Attributes.Add(new XmlSchemaAttribute
{
Name = "expressionLanguage",
Use = XmlSchemaUse.Optional,
SchemaTypeName =
new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
});
var element = new XmlSchemaElement
{
Name = "dicom-age-less-than",
SchemaType = type
};
return element;
}
示例2: CreateSimpletypeLength
private void CreateSimpletypeLength(string length, string minLength, string maxLength, bool expected) {
passed = true;
XmlSchema schema = new XmlSchema();
XmlSchemaSimpleType testType = new XmlSchemaSimpleType();
testType.Name = "TestType";
XmlSchemaSimpleTypeRestriction testTypeRestriction = new XmlSchemaSimpleTypeRestriction();
testTypeRestriction.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
if (length != "-") {
XmlSchemaLengthFacet _length = new XmlSchemaLengthFacet();
_length.Value = length;
testTypeRestriction.Facets.Add(_length);
}
if (minLength != "-") {
XmlSchemaMinLengthFacet _minLength = new XmlSchemaMinLengthFacet();
_minLength.Value = minLength;
testTypeRestriction.Facets.Add(_minLength);
}
if (maxLength != "-") {
XmlSchemaMaxLengthFacet _maxLength = new XmlSchemaMaxLengthFacet();
_maxLength.Value = maxLength;
testTypeRestriction.Facets.Add(_maxLength);
}
testType.Content = testTypeRestriction;
schema.Items.Add(testType);
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
Assert.IsTrue (expected == passed, (passed ? "Test passed, should have failed" : "Test failed, should have passed") + ": " + length + " " + minLength + " " + maxLength);
}
示例3: Visit
protected override void Visit(XmlSchemaSimpleTypeRestriction restriction)
{
PushNode(SimpleTypeStructureNodeType.Restriction, restriction);
var baseType = _schemaSet.ResolveType(restriction.BaseType, restriction.BaseTypeName);
Traverse(baseType);
Traverse(restriction.Facets);
PopNode();
}
示例4: CreateGuidType
private XmlSchemaSimpleType CreateGuidType()
{
var type = new XmlSchemaSimpleType { Name = "Guid" };
var restriction = new XmlSchemaSimpleTypeRestriction { BaseType = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String) };
restriction.Facets.Add(new XmlSchemaPatternFacet
{
Value =
@"[{(]?[0-9A-Fa-f]{8}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{4}\-?[0-9A-Fa-f]{12}[})]?|([!$])(\(var|\(loc|\(wix)\.[_A-Za-z][0-9A-Za-z_.]*\)"
});
type.Content = restriction;
return type;
}
示例5: Write
protected internal override void Write(XmlSchemaObject obj)
{
var simpleType = (XmlSchemaSimpleType) obj;
var restriction = new XmlSchemaSimpleTypeRestriction();
foreach (var facet in Facets)
{
restriction.Facets.Add(facet);
}
simpleType.Content = restriction;
base.Write(obj);
}
示例6: AddNonXsdPrimitive
private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
{
XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
Name = dataTypeName
};
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
BaseTypeName = baseTypeName
};
foreach (XmlSchemaFacet facet in facets)
{
restriction.Facets.Add(facet);
}
dataType.Content = restriction;
TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
if (primitiveTypes[type] == null)
{
primitiveTypes.Add(type, desc);
}
primitiveDataTypes.Add(dataType, desc);
primitiveNames.Add(dataTypeName, ns, desc);
}
示例7: GetSimpleType
/// <summary>
/// Returns a SimpleType restricted by the datatype only
/// </summary>
public override XmlSchemaSimpleType GetSimpleType(string attributeDataType)
{
var retVal = new XmlSchemaSimpleType();
// <xs:restriction base="<whatever xs:datatype is required>" />
var dataTypeRestriction = new XmlSchemaSimpleTypeRestriction
{
BaseTypeName = new XmlQualifiedName(attributeDataType)
};
retVal.Content = dataTypeRestriction;
// if the property type is an enum then add an enumeration facet to the simple type
if (Property.PropertyType.IsEnum)
{
// <xs:enumeration value="123" />
foreach (var enumValue in Enum.GetNames(Property.PropertyType))
{
var enumFacet = new XmlSchemaEnumerationFacet { Value = enumValue };
dataTypeRestriction.Facets.Add(enumFacet);
}
}
return retVal;
}
示例8: AddSimpleType
private static void AddSimpleType(XmlSchema schema, string typeName, string baseXsdType) {
XmlSchemaSimpleType type = new XmlSchemaSimpleType();
type.Name = typeName;
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.BaseTypeName = new XmlQualifiedName(baseXsdType, XmlSchema.Namespace);
type.Content = restriction;
schema.Items.Add(type);
}
示例9: ExportEnumMapping
XmlSchemaType ExportEnumMapping(EnumMapping mapping, string ns) {
if (!mapping.IncludeInSchema) throw new InvalidOperationException(Res.GetString(Res.XmlCannotIncludeInSchema, mapping.TypeDesc.Name));
XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)types[mapping];
if (dataType == null) {
CheckForDuplicateType(mapping, mapping.Namespace);
dataType = new XmlSchemaSimpleType();
dataType.Name = mapping.TypeName;
if (!mapping.IsAnonymousType) {
types.Add(mapping, dataType);
AddSchemaItem(dataType, mapping.Namespace, ns);
}
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
for (int i = 0; i < mapping.Constants.Length; i++) {
ConstantMapping constant = mapping.Constants[i];
XmlSchemaEnumerationFacet enumeration = new XmlSchemaEnumerationFacet();
enumeration.Value = constant.XmlName;
restriction.Facets.Add(enumeration);
}
if (!mapping.IsFlags) {
dataType.Content = restriction;
}
else {
XmlSchemaSimpleTypeList list = new XmlSchemaSimpleTypeList();
XmlSchemaSimpleType enumType = new XmlSchemaSimpleType();
enumType.Content = restriction;
list.ItemType = enumType;
dataType.Content = list;
}
}
if (!mapping.IsAnonymousType) {
AddSchemaImport(mapping.Namespace, ns);
}
return dataType;
}
示例10: GetBuildInSchema
internal static XmlSchema GetBuildInSchema()
{
if (builtInSchemaForXmlNS == null)
{
XmlSchema schema = new XmlSchema {
TargetNamespace = "http://www.w3.org/XML/1998/namespace"
};
schema.Namespaces.Add("xml", "http://www.w3.org/XML/1998/namespace");
XmlSchemaAttribute item = new XmlSchemaAttribute {
Name = "lang",
SchemaTypeName = new XmlQualifiedName("language", "http://www.w3.org/2001/XMLSchema")
};
schema.Items.Add(item);
XmlSchemaAttribute attribute2 = new XmlSchemaAttribute {
Name = "base",
SchemaTypeName = new XmlQualifiedName("anyURI", "http://www.w3.org/2001/XMLSchema")
};
schema.Items.Add(attribute2);
XmlSchemaAttribute attribute3 = new XmlSchemaAttribute {
Name = "space"
};
XmlSchemaSimpleType type = new XmlSchemaSimpleType();
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
BaseTypeName = new XmlQualifiedName("NCName", "http://www.w3.org/2001/XMLSchema")
};
XmlSchemaEnumerationFacet facet = new XmlSchemaEnumerationFacet {
Value = "default"
};
restriction.Facets.Add(facet);
XmlSchemaEnumerationFacet facet2 = new XmlSchemaEnumerationFacet {
Value = "preserve"
};
restriction.Facets.Add(facet2);
type.Content = restriction;
attribute3.SchemaType = type;
attribute3.DefaultValue = "preserve";
schema.Items.Add(attribute3);
XmlSchemaAttributeGroup group = new XmlSchemaAttributeGroup {
Name = "specialAttrs"
};
XmlSchemaAttribute attribute4 = new XmlSchemaAttribute {
RefName = new XmlQualifiedName("lang", "http://www.w3.org/XML/1998/namespace")
};
group.Attributes.Add(attribute4);
XmlSchemaAttribute attribute5 = new XmlSchemaAttribute {
RefName = new XmlQualifiedName("space", "http://www.w3.org/XML/1998/namespace")
};
group.Attributes.Add(attribute5);
XmlSchemaAttribute attribute6 = new XmlSchemaAttribute {
RefName = new XmlQualifiedName("base", "http://www.w3.org/XML/1998/namespace")
};
group.Attributes.Add(attribute6);
schema.Items.Add(group);
schema.IsPreprocessed = true;
schema.CompileSchemaInSet(new NameTable(), null, null);
Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, schema, null);
}
return builtInSchemaForXmlNS;
}
示例11: WriteEnumType
public XmlSchemaType WriteEnumType (Type type)
{
if (type.IsEnum == false)
throw new Exception (String.Format ("{0} is not an enumeration.", type.Name));
if (generatedSchemaTypes.Contains (type.FullName)) // Caching
return null;
XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType ();
simpleType.Name = type.Name;
FieldInfo [] fields = type.GetFields ();
XmlSchemaSimpleTypeRestriction simpleRestriction = new XmlSchemaSimpleTypeRestriction ();
simpleType.Content = simpleRestriction;
simpleRestriction.BaseTypeName = new XmlQualifiedName ("string", xs);
foreach (FieldInfo field in fields) {
if (field.IsSpecialName)
continue;
XmlSchemaEnumerationFacet e = new XmlSchemaEnumerationFacet ();
e.Value = field.Name;
simpleRestriction.Facets.Add (e);
}
generatedSchemaTypes.Add (type.FullName, simpleType);
return simpleType;
}
示例12: GetAttributeValueCompletionData
XmlCompletionDataCollection GetAttributeValueCompletionData(XmlSchemaSimpleTypeRestriction simpleTypeRestriction)
{
XmlCompletionDataCollection data = new XmlCompletionDataCollection();
foreach (XmlSchemaObject schemaObject in simpleTypeRestriction.Facets) {
XmlSchemaEnumerationFacet enumFacet = schemaObject as XmlSchemaEnumerationFacet;
if (enumFacet != null) {
AddAttributeValue(data, enumFacet.Value, enumFacet.Annotation);
}
}
return data;
}
示例13: FinishBuiltinType
/// <summary>
/// Finish constructing built-in types by setting up derivation and list links.
/// </summary>
internal static void FinishBuiltinType(XmlSchemaSimpleType derivedType, XmlSchemaSimpleType baseType) {
Debug.Assert(derivedType != null && baseType != null);
// Create link from the derived type to the base type
derivedType.SetBaseSchemaType(baseType);
derivedType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.Atomic) { //Content is restriction
XmlSchemaSimpleTypeRestriction restContent = new XmlSchemaSimpleTypeRestriction();
restContent.BaseTypeName = baseType.QualifiedName;
derivedType.Content = restContent;
}
// Create link from a list type to its member type
if (derivedType.Datatype.Variety == XmlSchemaDatatypeVariety.List) {
XmlSchemaSimpleTypeList listContent = new XmlSchemaSimpleTypeList();
derivedType.SetDerivedBy(XmlSchemaDerivationMethod.List);
switch (derivedType.Datatype.TypeCode) {
case XmlTypeCode.NmToken:
listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.NmToken];
break;
case XmlTypeCode.Entity:
listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Entity];
break;
case XmlTypeCode.Idref:
listContent.ItemType = listContent.BaseItemType = enumToTypeCode[(int) XmlTypeCode.Idref];
break;
}
derivedType.Content = listContent;
}
}
示例14: GetBuildInSchema
internal static XmlSchema GetBuildInSchema() {
if (builtInSchemaForXmlNS == null) {
XmlSchema tempSchema = new XmlSchema();
tempSchema.TargetNamespace = XmlReservedNs.NsXml;
tempSchema.Namespaces.Add("xml", XmlReservedNs.NsXml);
XmlSchemaAttribute lang = new XmlSchemaAttribute();
lang.Name = "lang";
lang.SchemaTypeName = new XmlQualifiedName("language", XmlReservedNs.NsXs);
tempSchema.Items.Add(lang);
XmlSchemaAttribute xmlbase = new XmlSchemaAttribute();
xmlbase.Name = "base";
xmlbase.SchemaTypeName = new XmlQualifiedName("anyURI", XmlReservedNs.NsXs);
tempSchema.Items.Add(xmlbase);
XmlSchemaAttribute space = new XmlSchemaAttribute();
space.Name = "space";
XmlSchemaSimpleType type = new XmlSchemaSimpleType();
XmlSchemaSimpleTypeRestriction r = new XmlSchemaSimpleTypeRestriction();
r.BaseTypeName = new XmlQualifiedName("NCName", XmlReservedNs.NsXs);
XmlSchemaEnumerationFacet space_default = new XmlSchemaEnumerationFacet();
space_default.Value = "default";
r.Facets.Add(space_default);
XmlSchemaEnumerationFacet space_preserve = new XmlSchemaEnumerationFacet();
space_preserve.Value = "preserve";
r.Facets.Add(space_preserve);
type.Content = r;
space.SchemaType = type;
space.DefaultValue = "preserve";
tempSchema.Items.Add(space);
XmlSchemaAttributeGroup attributeGroup = new XmlSchemaAttributeGroup();
attributeGroup.Name = "specialAttrs";
XmlSchemaAttribute langRef = new XmlSchemaAttribute();
langRef.RefName = new XmlQualifiedName("lang", XmlReservedNs.NsXml);
attributeGroup.Attributes.Add(langRef);
XmlSchemaAttribute spaceRef = new XmlSchemaAttribute();
spaceRef.RefName = new XmlQualifiedName("space", XmlReservedNs.NsXml);
attributeGroup.Attributes.Add(spaceRef);
XmlSchemaAttribute baseRef = new XmlSchemaAttribute();
baseRef.RefName = new XmlQualifiedName("base", XmlReservedNs.NsXml);
attributeGroup.Attributes.Add(baseRef);
tempSchema.Items.Add(attributeGroup);
tempSchema.IsPreprocessed = true;
tempSchema.CompileSchemaInSet(new NameTable(), null, null); //compile built-in schema
Interlocked.CompareExchange<XmlSchema>(ref builtInSchemaForXmlNS, tempSchema, null);
}
return builtInSchemaForXmlNS;
}
示例15: ExportStreamBody
protected void ExportStreamBody(WsdlNS.Message message, string wrapperName, string wrapperNs, string partName, string partNs, bool isRpc, bool skipSchemaExport)
{
XmlSchemaSet schemas = this.exporter.GeneratedXmlSchemas;
XmlSchema schema = SchemaHelper.GetSchema(DataContractSerializerMessageContractImporter.StreamBodyTypeName.Namespace, schemas);
if (!schema.SchemaTypes.Contains(DataContractSerializerMessageContractImporter.StreamBodyTypeName))
{
XmlSchemaSimpleType streamBodyType = new XmlSchemaSimpleType();
streamBodyType.Name = DataContractSerializerMessageContractImporter.StreamBodyTypeName.Name;
XmlSchemaSimpleTypeRestriction contentRestriction = new XmlSchemaSimpleTypeRestriction();
contentRestriction.BaseTypeName = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Base64Binary).QualifiedName;
streamBodyType.Content = contentRestriction;
SchemaHelper.AddTypeToSchema(streamBodyType, schema, schemas);
}
XmlSchemaSequence wrapperSequence = null;
if (!isRpc && wrapperName != null)
wrapperSequence = ExportWrappedPart(message, wrapperName, wrapperNs, schemas, skipSchemaExport);
MessagePartDescription streamPart = new MessagePartDescription(partName, partNs);
ExportMessagePart(message, streamPart, DataContractSerializerMessageContractImporter.StreamBodyTypeName, null/*xsdType*/, false/*isOptional*/, false/*isNillable*/, skipSchemaExport, !isRpc, wrapperNs, wrapperSequence, schemas);
}