2 // System.Xml.Schema.XmlSchemaAttributeGroupRef.cs
5 // Dwivedi, Ajay kumar Adwiv@Yahoo.com
6 // Atsushi Enomoto ginga@kit.hi-ho.ne.jp
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
;
33 namespace System
.Xml
.Schema
36 /// Summary description for XmlSchemaAttributeGroupRef.
38 public class XmlSchemaAttributeGroupRef
: XmlSchemaAnnotated
40 private XmlQualifiedName refName
;
41 const string xmlname
= "attributeGroup";
43 public XmlSchemaAttributeGroupRef()
45 refName
= XmlQualifiedName
.Empty
;
48 [System
.Xml
.Serialization
.XmlAttribute("ref")]
49 public XmlQualifiedName RefName
51 get{ return refName; }
52 set{ refName = value; }
56 /// 1. ref must be present
58 internal override int Compile(ValidationEventHandler h
, XmlSchema schema
)
60 // If this is already compiled this time, simply skip.
61 if (this.IsComplied (schema
.CompilationId
))
65 if(RefName
== null || RefName
.IsEmpty
)
66 error(h
, "ref must be present");
67 else if(!XmlSchemaUtil
.CheckQName(RefName
))
68 error(h
, "ref must be a valid qname");
70 XmlSchemaUtil
.CompileID(Id
,this, schema
.IDCollection
,h
);
72 this.CompilationId
= schema
.CompilationId
;
76 internal override int Validate(ValidationEventHandler h
, XmlSchema schema
)
84 // {any attributes with non-schema namespace . . .}>
85 // Content: (annotation?)
87 internal static XmlSchemaAttributeGroupRef
Read(XmlSchemaReader reader
, ValidationEventHandler h
)
89 XmlSchemaAttributeGroupRef attrgrp
= new XmlSchemaAttributeGroupRef();
90 reader
.MoveToElement();
92 if(reader
.NamespaceURI
!= XmlSchema
.Namespace
|| reader
.LocalName
!= xmlname
)
94 error(h
,"Should not happen :1: XmlSchemaAttributeGroupRef.Read, name="+reader
.Name
,null);
99 attrgrp
.LineNumber
= reader
.LineNumber
;
100 attrgrp
.LinePosition
= reader
.LinePosition
;
101 attrgrp
.SourceUri
= reader
.BaseURI
;
103 while(reader
.MoveToNextAttribute())
105 if(reader
.Name
== "id")
107 attrgrp
.Id
= reader
.Value
;
109 else if(reader
.Name
== "ref")
112 attrgrp
.refName
= XmlSchemaUtil
.ReadQNameAttribute(reader
,out innerex
);
114 error(h
, reader
.Value
+ " is not a valid value for ref attribute",innerex
);
116 else if((reader
.NamespaceURI
== "" && reader
.Name
!= "xmlns") || reader
.NamespaceURI
== XmlSchema
.Namespace
)
118 error(h
,reader
.Name
+ " is not a valid attribute for attributeGroup in this context",null);
122 XmlSchemaUtil
.ReadUnhandledAttribute(reader
,attrgrp
);
126 reader
.MoveToElement();
127 if(reader
.IsEmptyElement
)
131 while(reader
.ReadNextElement())
133 if(reader
.NodeType
== XmlNodeType
.EndElement
)
135 if(reader
.LocalName
!= xmlname
)
136 error(h
,"Should not happen :2: XmlSchemaAttributeGroupRef.Read, name="+reader
.Name
,null);
139 if(level
<= 1 && reader
.LocalName
== "annotation")
141 level
= 2; //Only one annotation
142 XmlSchemaAnnotation annotation
= XmlSchemaAnnotation
.Read(reader
,h
);
143 if(annotation
!= null)
144 attrgrp
.Annotation
= annotation
;
147 reader
.RaiseInvalidElementError();