2 // System.Xml.Schema.XmlSchemaAttributeGroupRef.cs
\r
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
\r
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
\r
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Xml.Serialization;
\r
33 namespace System.Xml.Schema
\r
36 /// Summary description for XmlSchemaAttributeGroupRef.
\r
38 public class XmlSchemaAttributeGroupRef : XmlSchemaAnnotated
\r
40 private XmlQualifiedName refName;
\r
41 const string xmlname = "attributeGroup";
\r
43 public XmlSchemaAttributeGroupRef()
\r
45 refName = XmlQualifiedName.Empty;
\r
48 [System.Xml.Serialization.XmlAttribute("ref")]
\r
49 public XmlQualifiedName RefName
\r
51 get{ return refName; }
\r
52 set{ refName = value; }
\r
56 /// 1. ref must be present
\r
58 internal override int Compile(ValidationEventHandler h, XmlSchema schema)
\r
60 // If this is already compiled this time, simply skip.
\r
61 if (CompilationId == schema.CompilationId)
\r
65 if(RefName == null || RefName.IsEmpty)
\r
66 error(h, "ref must be present");
\r
67 else if(!XmlSchemaUtil.CheckQName(RefName))
\r
68 error(h, "ref must be a valid qname");
\r
70 XmlSchemaUtil.CompileID(Id,this, schema.IDCollection,h);
\r
72 this.CompilationId = schema.CompilationId;
\r
76 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
\r
84 // {any attributes with non-schema namespace . . .}>
\r
85 // Content: (annotation?)
\r
87 internal static XmlSchemaAttributeGroupRef Read(XmlSchemaReader reader, ValidationEventHandler h)
\r
89 XmlSchemaAttributeGroupRef attrgrp = new XmlSchemaAttributeGroupRef();
\r
90 reader.MoveToElement();
\r
92 if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
\r
94 error(h,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
\r
99 attrgrp.LineNumber = reader.LineNumber;
\r
100 attrgrp.LinePosition = reader.LinePosition;
\r
101 attrgrp.SourceUri = reader.BaseURI;
\r
103 while(reader.MoveToNextAttribute())
\r
105 if(reader.Name == "id")
\r
107 attrgrp.Id = reader.Value;
\r
109 else if(reader.Name == "ref")
\r
112 attrgrp.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
\r
113 if(innerex != null)
\r
114 error(h, reader.Value + " is not a valid value for ref attribute",innerex);
\r
116 else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
\r
118 error(h,reader.Name + " is not a valid attribute for attributeGroup in this context",null);
\r
122 XmlSchemaUtil.ReadUnhandledAttribute(reader,attrgrp);
\r
126 reader.MoveToElement();
\r
127 if(reader.IsEmptyElement)
\r
131 while(reader.ReadNextElement())
\r
133 if(reader.NodeType == XmlNodeType.EndElement)
\r
135 if(reader.LocalName != xmlname)
\r
136 error(h,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader.Name,null);
\r
139 if(level <= 1 && reader.LocalName == "annotation")
\r
141 level = 2; //Only one annotation
\r
142 XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
\r
143 if(annotation != null)
\r
144 attrgrp.Annotation = annotation;
\r
147 reader.RaiseInvalidElementError();
\r