1 // Author: Dwivedi, Ajay kumar
\r
5 using System.Xml.Serialization;
\r
7 namespace System.Xml.Schema
\r
10 /// Summary description for XmlSchemaSimpleContentExtension.
\r
12 public class XmlSchemaSimpleContentExtension : XmlSchemaContent
\r
15 private XmlSchemaAnyAttribute any;
\r
16 private XmlSchemaObjectCollection attributes;
\r
17 private XmlQualifiedName baseTypeName;
\r
18 private static string xmlname = "extension";
\r
20 public XmlSchemaSimpleContentExtension()
\r
22 baseTypeName = XmlQualifiedName.Empty;
\r
23 attributes = new XmlSchemaObjectCollection();
\r
26 [XmlElement("anyAttribute",Namespace="http://www.w3.org/2001/XMLSchema")]
\r
27 public XmlSchemaAnyAttribute AnyAttribute
\r
33 [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
34 [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroupRef),Namespace="http://www.w3.org/2001/XMLSchema")]
\r
35 public XmlSchemaObjectCollection Attributes
\r
37 get{ return attributes; }
\r
40 [System.Xml.Serialization.XmlAttribute("base")]
\r
41 public XmlQualifiedName BaseTypeName
\r
43 get{ return baseTypeName; }
\r
44 set{ baseTypeName = value; }
\r
47 /// 1. Base must be present and a QName
\r
50 internal int Compile(ValidationEventHandler h, XmlSchemaInfo info)
\r
52 if(BaseTypeName == null || BaseTypeName.IsEmpty)
\r
54 error(h, "base must be present and a QName");
\r
57 if(this.AnyAttribute != null)
\r
59 AnyAttribute.Compile(h,info);
\r
62 foreach(XmlSchemaObject obj in Attributes)
\r
64 if(obj is XmlSchemaAttribute)
\r
66 XmlSchemaAttribute attr = (XmlSchemaAttribute) obj;
\r
67 attr.Compile(h,info);
\r
69 else if(obj is XmlSchemaAttributeGroup)
\r
71 XmlSchemaAttributeGroup atgrp = (XmlSchemaAttributeGroup) obj;
\r
72 atgrp.Compile(h,info);
\r
75 error(h,obj.GetType() +" is not valid in this place::SimpleConentExtension");
\r
77 if(this.Id != null && !XmlSchemaUtil.CheckID(Id))
\r
78 error(h, "id must be a valid ID");
\r
84 internal int Validate(ValidationEventHandler h)
\r
91 //{any attributes with non-schema namespace . . .}>
\r
92 //Content: (annotation?, ((attribute | attributeGroup)*, anyAttribute?))
\r
94 internal static XmlSchemaSimpleContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
96 XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
\r
97 reader.MoveToElement();
\r
99 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
101 error(h,"Should not happen :1: XmlSchemaAttributeGroup.Read, name="+reader.Name,null);
\r
106 extension.LineNumber = reader.LineNumber;
\r
107 extension.LinePosition = reader.LinePosition;
\r
108 extension.SourceUri = reader.BaseURI;
\r
110 while(reader.MoveToNextAttribute())
\r
112 if(reader.Name == "base")
\r
115 extension.baseTypeName= XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
116 if(innerex != null)
\r
117 error(h, reader.Value + " is not a valid value for base attribute",innerex);
\r
119 else if(reader.Name == "id")
\r
121 extension.Id = reader.Value;
\r
123 else if(reader.NamespaceURI == "" || reader.NamespaceURI == XmlSchema.Namespace)
\r
125 error(h,reader.Name + " is not a valid attribute for extension in this context",null);
\r
129 //TODO: Add to Unhandled attributes
\r
133 reader.MoveToElement();
\r
134 if(reader.IsEmptyElement)
\r
137 //Content: 1.annotation?, 2.(attribute | attributeGroup)*, 3.anyAttribute?
\r
139 while(reader.ReadNextElement())
\r
141 if(reader.NodeType == XmlNodeType.EndElement)
\r
143 if(reader.LocalName != xmlname)
\r
144 error(h,"Should not happen :2: XmlSchemaSimpleContentExtension.Read, name="+reader.Name,null);
\r
147 if(level <= 1 && reader.LocalName == "annotation")
\r
149 level = 2; //Only one annotation
\r
150 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
151 if(annotation != null)
\r
152 extension.Annotation = annotation;
\r
157 if(reader.LocalName == "attribute")
\r
160 XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader,h);
\r
162 extension.Attributes.Add(attr);
\r
165 if(reader.LocalName == "attributeGroup")
\r
168 XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader,h);
\r
170 extension.attributes.Add(attr);
\r
174 if(level <= 3 && reader.LocalName == "anyAttribute")
\r
177 XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader,h);
\r
178 if(anyattr != null)
\r
179 extension.AnyAttribute = anyattr;
\r
182 reader.RaiseInvalidElementError();
\r