本文整理汇总了C#中System.Xml.Schema.XmlSchemaChoice类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaChoice类的具体用法?C# XmlSchemaChoice怎么用?C# XmlSchemaChoice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemaChoice类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaChoice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitXmlSchemaChoice
public virtual void VisitXmlSchemaChoice(XmlSchemaChoice choice)
{
foreach (XmlSchemaObject o in choice.Items)
{
Dispatch(o);
}
}
示例2: CreateXmlSchemaForIndicatorsInGroup
/// <summary>
/// Формируем XmlSchema для правильного отображения индикаторов группы в VGridControl
/// </summary>
/// <param name="elmList">названия всех по</param>
/// <returns>Возвращаем поток в который записана XmlSchema</returns>
public static MemoryStream CreateXmlSchemaForIndicatorsInGroup(List<string[]> elmList)
{
var xmlSchema = new XmlSchema();
// <xs:element name="root">
var elementRoot = new XmlSchemaElement();
xmlSchema.Items.Add(elementRoot);
elementRoot.Name = "root";
// <xs:complexType>
var complexType = new XmlSchemaComplexType();
elementRoot.SchemaType = complexType;
// <xs:choice minOccurs="0" maxOccurs="unbounded">
var choice = new XmlSchemaChoice();
complexType.Particle = choice;
choice.MinOccurs = 0;
choice.MaxOccursString = "unbounded";
// <xs:element name="record">
var elementRecord = new XmlSchemaElement();
choice.Items.Add(elementRecord);
elementRecord.Name = "record";
// <xs:complexType>
var complexType2 = new XmlSchemaComplexType();
elementRecord.SchemaType = complexType2;
// <xs:sequence>
var sequence = new XmlSchemaSequence();
complexType2.Particle = sequence;
foreach (var el in elmList)
{
var element = new XmlSchemaElement();
sequence.Items.Add(element);
element.Name = el[0];
element.SchemaTypeName = new XmlQualifiedName(el[1], "http://www.w3.org/2001/XMLSchema");
}
var schemaSet = new XmlSchemaSet();
schemaSet.Add(xmlSchema);
schemaSet.Compile();
XmlSchema compiledSchema = null;
foreach (XmlSchema schema1 in schemaSet.Schemas())
compiledSchema = schema1;
var nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
var ms = new MemoryStream();
if (compiledSchema != null) compiledSchema.Write(ms, nsmgr);
ms.Position = 0;
return ms;
}
示例3: Write
protected internal override void Write(XmlSchemaObject obj)
{
var type = (XmlSchemaComplexType) obj;
var choice = new XmlSchemaChoice {MinOccurs = 0};
if (MaxOccurs != null)
{
choice.MaxOccurs = MaxOccurs.Value;
}
foreach (var choiceType in Types)
{
var element = new XmlSchemaElement();
choiceType.Write(element);
choice.Items.Add(element);
}
type.Particle = choice;
base.Write(obj);
}
示例4: CannonicalizeChoice
private XmlSchemaParticle CannonicalizeChoice(XmlSchemaChoice choice, bool root, bool substitution)
{
XmlSchemaChoice source = choice;
if (choice.Items.Count > 0)
{
XmlSchemaChoice choice3 = new XmlSchemaChoice {
MinOccurs = choice.MinOccurs,
MaxOccurs = choice.MaxOccurs
};
for (int i = 0; i < choice.Items.Count; i++)
{
XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaParticle) choice.Items[i], false, substitution);
if (item != XmlSchemaParticle.Empty)
{
if (((item.MinOccurs == 1M) && (item.MaxOccurs == 1M)) && (item is XmlSchemaChoice))
{
XmlSchemaChoice choice4 = (XmlSchemaChoice) item;
for (int j = 0; j < choice4.Items.Count; j++)
{
choice3.Items.Add(choice4.Items[j]);
}
}
else
{
choice3.Items.Add(item);
}
}
}
choice = choice3;
}
if (!root && (choice.Items.Count == 0))
{
if (choice.MinOccurs != 0M)
{
base.SendValidationEvent("Sch_EmptyChoice", source, XmlSeverityType.Warning);
}
return XmlSchemaParticle.Empty;
}
if ((!root && (choice.Items.Count == 1)) && ((choice.MinOccurs == 1M) && (choice.MaxOccurs == 1M)))
{
return (XmlSchemaParticle) choice.Items[0];
}
return choice;
}
示例5: Write52_XmlSchemaChoice
void Write52_XmlSchemaChoice(XmlSchemaChoice o) {
if ((object)o == null) return;
System.Type t = o.GetType();
WriteStartElement("choice");
WriteAttribute(@"id", @"", ((System.String)[email protected]));
WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs));
WriteAttribute(@"maxOccurs", @"", o.MaxOccurs == decimal.MaxValue ? "unbounded" : XmlConvert.ToString(o.MaxOccurs));
WriteAttributes((XmlAttribute[])[email protected], o);
Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)[email protected]);
WriteSortedItems([email protected]);
WriteEndElement();
}
示例6: SetContainer
private void SetContainer(State state, object container) {
switch (state) {
case State.Root:
break;
case State.Schema:
break;
case State.Annotation:
this.annotation = (XmlSchemaAnnotation)container;
break;
case State.Include:
this.include = (XmlSchemaInclude)container;
break;
case State.Import:
this.import = (XmlSchemaImport)container;
break;
case State.Element:
this.element = (XmlSchemaElement)container;
break;
case State.Attribute:
this.attribute = (XmlSchemaAttribute)container;
break;
case State.AttributeGroup:
this.attributeGroup = (XmlSchemaAttributeGroup)container;
break;
case State.AttributeGroupRef:
this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
break;
case State.AnyAttribute:
this.anyAttribute = (XmlSchemaAnyAttribute)container;
break;
case State.Group:
this.group = (XmlSchemaGroup)container;
break;
case State.GroupRef:
this.groupRef = (XmlSchemaGroupRef)container;
break;
case State.All:
this.all = (XmlSchemaAll)container;
break;
case State.Choice:
this.choice = (XmlSchemaChoice)container;
break;
case State.Sequence:
this.sequence = (XmlSchemaSequence)container;
break;
case State.Any:
this.anyElement = (XmlSchemaAny)container;
break;
case State.Notation:
this.notation = (XmlSchemaNotation)container;
break;
case State.SimpleType:
this.simpleType = (XmlSchemaSimpleType)container;
break;
case State.ComplexType:
this.complexType = (XmlSchemaComplexType)container;
break;
case State.ComplexContent:
this.complexContent = (XmlSchemaComplexContent)container;
break;
case State.ComplexContentExtension:
this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
break;
case State.ComplexContentRestriction:
this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
break;
case State.SimpleContent:
this.simpleContent = (XmlSchemaSimpleContent)container;
break;
case State.SimpleContentExtension:
this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
break;
case State.SimpleContentRestriction:
this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
break;
case State.SimpleTypeUnion:
this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
break;
case State.SimpleTypeList:
this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
break;
case State.SimpleTypeRestriction:
this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
break;
case State.Unique:
case State.Key:
case State.KeyRef:
this.identityConstraint = (XmlSchemaIdentityConstraint)container;
break;
case State.Selector:
case State.Field:
this.xpath = (XmlSchemaXPath)container;
break;
case State.MinExclusive:
case State.MinInclusive:
case State.MaxExclusive:
case State.MaxInclusive:
case State.TotalDigits:
case State.FractionDigits:
case State.Length:
//.........这里部分代码省略.........
示例7: IsSequenceFromChoice
private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice) {
decimal minOccurs, maxOccurs;
minOccurs = derivedSequence.MinOccurs * derivedSequence.Items.Count;
if (derivedSequence.MaxOccurs == decimal.MaxValue) {
maxOccurs = decimal.MaxValue;
}
else {
maxOccurs = derivedSequence.MaxOccurs * derivedSequence.Items.Count;
}
if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseChoice.MinOccurs, baseChoice.MaxOccurs) || derivedSequence.Items.Count > baseChoice.Items.Count) {
return false;
}
for (int i = 0; i < derivedSequence.Items.Count; ++i) {
if (GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[i], baseChoice.Items) < 0)
return false;
}
return true;
}
示例8: IsElementFromGroupBase
private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase) {
if (baseGroupBase is XmlSchemaSequence) {
XmlSchemaSequence virtualSeq = new XmlSchemaSequence();
virtualSeq.MinOccurs = 1;
virtualSeq.MaxOccurs = 1;
virtualSeq.Items.Add(derivedElement);
if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualSeq, baseGroupBase, true)) {
return true;
}
restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase1, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
}
else if (baseGroupBase is XmlSchemaChoice) {
XmlSchemaChoice virtualChoice = new XmlSchemaChoice();
virtualChoice.MinOccurs = 1;
virtualChoice.MaxOccurs = 1;
virtualChoice.Items.Add(derivedElement);
if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualChoice, baseGroupBase, false)) {
return true;
}
restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase2, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
}
else if (baseGroupBase is XmlSchemaAll) {
XmlSchemaAll virtualAll = new XmlSchemaAll();
virtualAll.MinOccurs = 1;
virtualAll.MaxOccurs = 1;
virtualAll.Items.Add(derivedElement);
if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualAll, baseGroupBase, true)) {
return true;
}
restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase3, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
}
return false;
}
示例9: ExportElementAccessors
private void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns)
{
if (accessors.Length != 0)
{
if (accessors.Length == 1)
{
this.ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns);
}
else
{
XmlSchemaChoice choice = new XmlSchemaChoice {
MaxOccurs = repeats ? 79228162514264337593543950335M : 1M,
MinOccurs = repeats ? 0 : 1
};
for (int i = 0; i < accessors.Length; i++)
{
this.ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns);
}
if (choice.Items.Count > 0)
{
group.Items.Add(choice);
}
}
}
}
示例10: CreateTriggerBodyType
/// <summary>
/// Creates the schema type representing the contents of a trigger type
/// </summary>
/// <returns>Type definition for an agent</returns>
static XmlSchemaType CreateTriggerBodyType()
{
XmlSchemaChoice TriggerChoice = new XmlSchemaChoice();
TriggerChoice.MinOccurs = 0;
TriggerChoice.MaxOccursString = "unbounded";
TriggerChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
TriggerChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
TriggerChoice.Items.Add(CreateSchemaElement("Agent", ScriptSchemaStandardType.Agent));
TriggerChoice.Items.Add(CreateSchemaElement("Aggregate", ScriptSchemaStandardType.Aggregate));
TriggerChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
TriggerChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
TriggerChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.TriggerBody));
TriggerChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.TriggerBody));
TriggerChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.TriggerBody));
XmlSchemaComplexType TriggerType = new XmlSchemaComplexType();
TriggerType.Name = GetTypeName(ScriptSchemaStandardType.TriggerBody);
TriggerType.Particle = TriggerChoice;
return TriggerType;
}
示例11: CreateGraphType
/// <summary>
/// Creates the schema type representing the graph type
/// </summary>
/// <returns>Type definition for a graph</returns>
static XmlSchemaType CreateGraphType()
{
XmlSchemaChoice GraphChoice = new XmlSchemaChoice();
GraphChoice.MinOccurs = 0;
GraphChoice.MaxOccursString = "unbounded";
GraphChoice.Items.Add(CreateSchemaElement("Include", ScriptSchemaStandardType.Include));
GraphChoice.Items.Add(CreateSchemaElement("Option", ScriptSchemaStandardType.Option));
GraphChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
GraphChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
GraphChoice.Items.Add(CreateSchemaElement("Agent", ScriptSchemaStandardType.Agent));
GraphChoice.Items.Add(CreateSchemaElement("Trigger", ScriptSchemaStandardType.Trigger));
GraphChoice.Items.Add(CreateSchemaElement("Aggregate", ScriptSchemaStandardType.Aggregate));
GraphChoice.Items.Add(CreateSchemaElement("Report", ScriptSchemaStandardType.Report));
GraphChoice.Items.Add(CreateSchemaElement("Badge", ScriptSchemaStandardType.Badge));
GraphChoice.Items.Add(CreateSchemaElement("Notify", ScriptSchemaStandardType.Notify));
GraphChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
GraphChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
GraphChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.Graph));
GraphChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.Graph));
GraphChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.Graph));
XmlSchemaComplexType GraphType = new XmlSchemaComplexType();
GraphType.Name = GetTypeName(ScriptSchemaStandardType.Graph);
GraphType.Particle = GraphChoice;
return GraphType;
}
示例12: GetSchemaArrayElement
XmlSchemaParticle GetSchemaArrayElement (XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
{
int numInfos = infos.Count;
if (numInfos > 0 && ((XmlTypeMapElementInfo)infos[0]).IsTextElement) numInfos--;
if (numInfos == 0) return null;
if (numInfos == 1)
{
XmlSchemaParticle selem = GetSchemaElement (currentSchema, (XmlTypeMapElementInfo) infos[infos.Count-1], true);
selem.MinOccursString = "0";
selem.MaxOccursString = "unbounded";
return selem;
}
else
{
XmlSchemaChoice schoice = new XmlSchemaChoice ();
schoice.MinOccursString = "0";
schoice.MaxOccursString = "unbounded";
foreach (XmlTypeMapElementInfo einfo in infos)
{
if (einfo.IsTextElement) continue;
schoice.Items.Add (GetSchemaElement (currentSchema, einfo, true));
}
return schoice;
}
}
示例13: GetOptimizedParticle
internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
{
if (OptimizedParticle != null)
return OptimizedParticle;
if (Items.Count == 0 || ValidatedMaxOccurs == 0)
OptimizedParticle = XmlSchemaParticle.Empty;
// LAMESPEC: Regardless of isTop, it should remove pointless particle. It seems ContentTypeParticle design bug.
else if (!isTop && Items.Count == 1 && ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
OptimizedParticle = ((XmlSchemaParticle) Items [0]).GetOptimizedParticle (false);
else {
XmlSchemaChoice c = new XmlSchemaChoice ();
CopyInfo (c);
for (int i = 0; i < Items.Count; i++) {
XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
p = p.GetOptimizedParticle (false);
if (p == XmlSchemaParticle.Empty)
continue;
else if (p is XmlSchemaChoice && p.ValidatedMinOccurs == 1 && p.ValidatedMaxOccurs == 1) {
XmlSchemaChoice pc = p as XmlSchemaChoice;
for (int ci = 0; ci < pc.Items.Count; ci++) {
c.Items.Add (pc.Items [ci]);
c.CompiledItems.Add (pc.Items [ci]);
}
}
else {
c.Items.Add (p);
c.CompiledItems.Add (p);
}
}
if (c.Items.Count == 0)
OptimizedParticle = XmlSchemaParticle.Empty;
else
OptimizedParticle = c;
}
return OptimizedParticle;
}
示例14: Read
//<choice
// id = ID
// maxOccurs = (nonNegativeInteger | unbounded) : 1
// minOccurs = nonNegativeInteger : 1
// {any attributes with non-schema namespace . . .}>
// Content: (annotation?, (element | group | choice | sequence | any)*)
//</choice>
internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
{
XmlSchemaChoice choice = new XmlSchemaChoice();
reader.MoveToElement();
if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
{
error(h,"Should not happen :1: XmlSchemaChoice.Read, name="+reader.Name,null);
reader.SkipToEnd();
return null;
}
choice.LineNumber = reader.LineNumber;
choice.LinePosition = reader.LinePosition;
choice.SourceUri = reader.BaseURI;
while(reader.MoveToNextAttribute())
{
if(reader.Name == "id")
{
choice.Id = reader.Value;
}
else if(reader.Name == "maxOccurs")
{
try
{
choice.MaxOccursString = reader.Value;
}
catch(Exception e)
{
error(h,reader.Value + " is an invalid value for maxOccurs",e);
}
}
else if(reader.Name == "minOccurs")
{
try
{
choice.MinOccursString = reader.Value;
}
catch(Exception e)
{
error(h,reader.Value + " is an invalid value for minOccurs",e);
}
}
else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
{
error(h,reader.Name + " is not a valid attribute for choice",null);
}
else
{
XmlSchemaUtil.ReadUnhandledAttribute(reader,choice);
}
}
reader.MoveToElement();
if(reader.IsEmptyElement)
return choice;
// Content: (annotation?, (element | group | choice | sequence | any)*)
int level = 1;
while(reader.ReadNextElement())
{
if(reader.NodeType == XmlNodeType.EndElement)
{
if(reader.LocalName != xmlname)
error(h,"Should not happen :2: XmlSchemaChoice.Read, name="+reader.Name,null);
break;
}
if(level <= 1 && reader.LocalName == "annotation")
{
level = 2; //Only one annotation
XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
if(annotation != null)
choice.Annotation = annotation;
continue;
}
if(level <=2)
{
if(reader.LocalName == "element")
{
level = 2;
XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
if(element != null)
choice.items.Add(element);
continue;
}
if(reader.LocalName == "group")
{
level = 2;
XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
if(group != null)
choice.items.Add(group);
continue;
//.........这里部分代码省略.........
示例15: CreateTaskListComplexType
protected XmlSchemaComplexType CreateTaskListComplexType(Type[] tasks, Type[] dataTypes, bool includeProjectLevelItems)
{
XmlSchemaComplexType tasklistCT = new XmlSchemaComplexType();
XmlSchemaChoice choice = new XmlSchemaChoice();
choice.MinOccurs = 0;
choice.MaxOccursString = "unbounded";
tasklistCT.Particle = choice;
foreach (Type t in tasks) {
XmlSchemaElement taskElement = new XmlSchemaElement();
string typeId = GenerateIDFromType(t);
XmlSchemaComplexType taskCT = FindComplexTypeByID(typeId);
taskElement.Name = GetTaskName(t);
taskElement.SchemaTypeName = taskCT.QualifiedName;
choice.Items.Add(taskElement);
}
foreach (Type t in dataTypes) {
XmlSchemaElement dataTypeElement = new XmlSchemaElement();
string typeId = GenerateIDFromType(t);
XmlSchemaComplexType dataTypeCT = FindComplexTypeByID(typeId);
dataTypeElement.Name = GetDataTypeName(t);
dataTypeElement.SchemaTypeName = dataTypeCT.QualifiedName;
choice.Items.Add(dataTypeElement);
}
if (includeProjectLevelItems) {
XmlSchemaElement targetElement = new XmlSchemaElement();
targetElement.Name = "target";
targetElement.SchemaTypeName = _targetCT.QualifiedName;
choice.Items.Add(targetElement);
}
return tasklistCT;