XmlSchemaElement.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml;
  5. using System.Xml.Serialization;
  6. using System.ComponentModel;
  7. namespace System.Xml.Schema
  8. {
  9. /// <summary>
  10. /// Summary description for XmlSchemaElement.
  11. /// </summary>
  12. public class XmlSchemaElement : XmlSchemaParticle
  13. {
  14. private XmlSchemaDerivationMethod block;
  15. private XmlSchemaDerivationMethod blockResolved;
  16. private XmlSchemaObjectCollection constraints;
  17. private string defaultValue;
  18. private object elementType;
  19. private XmlSchemaDerivationMethod final;
  20. private XmlSchemaDerivationMethod finalResolved;
  21. private string fixedValue;
  22. private XmlSchemaForm form;
  23. private bool isAbstract;
  24. private bool isNillable;
  25. private string name;
  26. private XmlQualifiedName qName;
  27. private XmlQualifiedName refName;
  28. private XmlSchemaType schemaType;
  29. private XmlQualifiedName schemaTypeName;
  30. private XmlQualifiedName substitutionGroup;
  31. internal bool parentIsSchema = false;
  32. private string targetNamespace;
  33. private string hash;
  34. private static string xmlname = "element";
  35. public XmlSchemaElement()
  36. {
  37. block = XmlSchemaDerivationMethod.None;
  38. final = XmlSchemaDerivationMethod.None;
  39. constraints = new XmlSchemaObjectCollection();
  40. qName = XmlQualifiedName.Empty;
  41. refName = XmlQualifiedName.Empty;
  42. schemaTypeName = XmlQualifiedName.Empty;
  43. substitutionGroup = XmlQualifiedName.Empty;
  44. substitutionGroup = XmlQualifiedName.Empty;
  45. }
  46. #region Attributes
  47. [DefaultValue(false)]
  48. [System.Xml.Serialization.XmlAttribute("abstract")]
  49. public bool IsAbstract
  50. {
  51. get{ return isAbstract; }
  52. set{ isAbstract = value; }
  53. }
  54. [DefaultValue(XmlSchemaDerivationMethod.None)]
  55. [System.Xml.Serialization.XmlAttribute("block")]
  56. public XmlSchemaDerivationMethod Block
  57. {
  58. get{ return block; }
  59. set{ block = value; }
  60. }
  61. [DefaultValue(null)]
  62. [System.Xml.Serialization.XmlAttribute("default")]
  63. public string DefaultValue
  64. {
  65. get{ return defaultValue; }
  66. set{ defaultValue = value; }
  67. }
  68. [DefaultValue(XmlSchemaDerivationMethod.None)]
  69. [System.Xml.Serialization.XmlAttribute("final")]
  70. public XmlSchemaDerivationMethod Final
  71. {
  72. get{ return final; }
  73. set{ final = value; }
  74. }
  75. [DefaultValue(null)]
  76. [System.Xml.Serialization.XmlAttribute("fixed")]
  77. public string FixedValue
  78. {
  79. get{ return fixedValue; }
  80. set{ fixedValue = value; }
  81. }
  82. [DefaultValue(XmlSchemaForm.None)]
  83. [System.Xml.Serialization.XmlAttribute("form")]
  84. public XmlSchemaForm Form
  85. {
  86. get{ return form; }
  87. set{ form = value; }
  88. }
  89. [DefaultValue(null)]
  90. [System.Xml.Serialization.XmlAttribute("name")]
  91. public string Name
  92. {
  93. get{ return name; }
  94. set{ name = value; }
  95. }
  96. [DefaultValue(false)]
  97. [System.Xml.Serialization.XmlAttribute("nillable")]
  98. public bool IsNillable
  99. {
  100. get{ return isNillable; }
  101. set{ isNillable = value; }
  102. }
  103. [System.Xml.Serialization.XmlAttribute("ref")]
  104. public XmlQualifiedName RefName
  105. {
  106. get{ return refName; }
  107. set{ refName = value;}
  108. }
  109. [System.Xml.Serialization.XmlAttribute("substitutionGroup")]
  110. public XmlQualifiedName SubstitutionGroup
  111. {
  112. get{ return substitutionGroup; }
  113. set{ substitutionGroup = value; }
  114. }
  115. [System.Xml.Serialization.XmlAttribute("type")]
  116. public XmlQualifiedName SchemaTypeName
  117. {
  118. get{ return schemaTypeName; }
  119. set{ schemaTypeName = value; }
  120. }
  121. [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace="http://www.w3.org/2001/XMLSchema")]
  122. [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace="http://www.w3.org/2001/XMLSchema")]
  123. public XmlSchemaType SchemaType
  124. {
  125. get{ return schemaType; }
  126. set{ schemaType = value; }
  127. }
  128. [XmlElement("unique",typeof(XmlSchemaUnique),Namespace="http://www.w3.org/2001/XMLSchema")]
  129. [XmlElement("key",typeof(XmlSchemaKey),Namespace="http://www.w3.org/2001/XMLSchema")]
  130. [XmlElement("keyref",typeof(XmlSchemaKeyref),Namespace="http://www.w3.org/2001/XMLSchema")]
  131. public XmlSchemaObjectCollection Constraints
  132. {
  133. get{ return constraints; }
  134. }
  135. [XmlIgnore]
  136. public XmlQualifiedName QualifiedName
  137. {
  138. get{ return qName; }
  139. }
  140. [XmlIgnore]
  141. public object ElementType
  142. {
  143. get{ return elementType; }
  144. }
  145. [XmlIgnore]
  146. public XmlSchemaDerivationMethod BlockResolved
  147. {
  148. get{ return blockResolved; }
  149. }
  150. [XmlIgnore]
  151. public XmlSchemaDerivationMethod FinalResolved
  152. {
  153. get{ return finalResolved; }
  154. }
  155. #endregion
  156. /// <remarks>
  157. /// a) If Element has parent as schema:
  158. /// 1. name must be present and of type NCName.
  159. /// 2. ref must be absent
  160. /// 3. form must be absent
  161. /// 4. minOccurs must be absent
  162. /// 5. maxOccurs must be absent
  163. /// b) If Element has parent is not schema and ref is absent
  164. /// 1. name must be present and of type NCName.
  165. /// 2. if form equals qualified or form is absent and schema's formdefault is qualifed,
  166. /// targetNamespace is schema's targetnamespace else empty.
  167. /// 3. type and either <simpleType> or <complexType> are mutually exclusive
  168. /// 4. default and fixed must not both be present.
  169. /// 5. substitutiongroup must be absent
  170. /// 6. final must be absent
  171. /// 7. abstract must be absent
  172. /// c) if the parent is not schema and ref is set
  173. /// 1. name must not be present
  174. /// 2. all of <simpleType>,<complexType>, <key>, <keyref>, <unique>, nillable,
  175. /// default, fixed, form, block and type, must be absent.
  176. /// 3. substitutiongroup is prohibited
  177. /// 4. final is prohibited
  178. /// 5. abstract is prohibited
  179. /// 6. default and fixed must not both be present.(Actually both are absent)
  180. /// </remarks>
  181. [MonoTODO]
  182. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  183. {
  184. // If this is already compiled this time, simply skip.
  185. if (this.IsComplied (schema.CompilationId))
  186. return 0;
  187. if(this.defaultValue != null && this.fixedValue != null)
  188. error(h,"both default and fixed can't be present");
  189. if(parentIsSchema)
  190. {
  191. if(this.refName != null && !RefName.IsEmpty)
  192. error(h,"ref must be absent");
  193. if(this.name == null) //b1
  194. error(h,"Required attribute name must be present");
  195. else if(!XmlSchemaUtil.CheckNCName(this.name)) // b1.2
  196. error(h,"attribute name must be NCName");
  197. else
  198. this.qName = new XmlQualifiedName(this.name, schema.TargetNamespace);
  199. if(form != XmlSchemaForm.None)
  200. error(h,"form must be absent");
  201. if(MinOccursString != null)
  202. error(h,"minOccurs must be absent");
  203. if(MaxOccursString != null)
  204. error(h,"maxOccurs must be absent");
  205. XmlSchemaDerivationMethod allfinal = (XmlSchemaDerivationMethod.Extension | XmlSchemaDerivationMethod.Restriction);
  206. if(final == XmlSchemaDerivationMethod.All)
  207. finalResolved = allfinal;
  208. else if(final == XmlSchemaDerivationMethod.None)
  209. finalResolved = allfinal;
  210. else
  211. {
  212. if((final & ~allfinal) != 0)
  213. warn(h,"some values for final are invalid in this context");
  214. finalResolved = final & allfinal;
  215. }
  216. XmlSchemaDerivationMethod allblock = XmlSchemaDerivationMethod.Extension |
  217. XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution;
  218. if(block == XmlSchemaDerivationMethod.All)
  219. blockResolved = allblock;
  220. else if(block == XmlSchemaDerivationMethod.None)
  221. blockResolved = allblock;
  222. else
  223. {
  224. if((block & ~allblock) != 0)
  225. warn(h,"Some of the values for block are invalid in this context");
  226. blockResolved = block & allblock;
  227. }
  228. if(schemaType != null && schemaTypeName != null && !schemaTypeName.IsEmpty)
  229. {
  230. error(h,"both schemaType and content can't be present");
  231. }
  232. //Even if both are present, read both of them.
  233. if(schemaType != null)
  234. {
  235. if(schemaType is XmlSchemaSimpleType)
  236. {
  237. errorCount += ((XmlSchemaSimpleType)schemaType).Compile(h,schema);
  238. }
  239. else if(schemaType is XmlSchemaComplexType)
  240. {
  241. errorCount += ((XmlSchemaComplexType)schemaType).Compile(h,schema);
  242. }
  243. else
  244. error(h,"only simpletype or complextype is allowed");
  245. }
  246. if(schemaTypeName != null && !schemaTypeName.IsEmpty)
  247. {
  248. if(!XmlSchemaUtil.CheckQName(SchemaTypeName))
  249. error(h,"SchemaTypeName must be an XmlQualifiedName");
  250. }
  251. if(SubstitutionGroup != null && !SubstitutionGroup.IsEmpty)
  252. {
  253. if(!XmlSchemaUtil.CheckQName(SubstitutionGroup))
  254. error(h,"SubstitutionGroup must be a valid XmlQualifiedName");
  255. }
  256. foreach(XmlSchemaObject obj in constraints)
  257. {
  258. if(obj is XmlSchemaUnique)
  259. errorCount += ((XmlSchemaUnique)obj).Compile(h,schema);
  260. else if(obj is XmlSchemaKey)
  261. errorCount += ((XmlSchemaKey)obj).Compile(h,schema);
  262. else if(obj is XmlSchemaKeyref)
  263. errorCount += ((XmlSchemaKeyref)obj).Compile(h,schema);
  264. }
  265. }
  266. else
  267. {
  268. if(substitutionGroup != null && !substitutionGroup.IsEmpty)
  269. error(h,"substitutionGroup must be absent");
  270. if(final != XmlSchemaDerivationMethod.None)
  271. error(h,"final must be absent");
  272. if(isAbstract)
  273. error(h,"abstract must be absent");
  274. //FIXME: Should we reset the values
  275. if(MinOccurs > MaxOccurs)
  276. error(h,"minOccurs must be less than or equal to maxOccurs");
  277. if(refName == null || RefName.IsEmpty)
  278. {
  279. if(form == XmlSchemaForm.Qualified || (form == XmlSchemaForm.None && schema.ElementFormDefault == XmlSchemaForm.Qualified))
  280. this.targetNamespace = schema.TargetNamespace;
  281. else
  282. this.targetNamespace = string.Empty;
  283. if(this.name == null) //b1
  284. error(h,"Required attribute name must be present");
  285. else if(!XmlSchemaUtil.CheckNCName(this.name)) // b1.2
  286. error(h,"attribute name must be NCName");
  287. else
  288. this.qName = new XmlQualifiedName(this.name, this.targetNamespace);
  289. XmlSchemaDerivationMethod allblock = XmlSchemaDerivationMethod.Extension |
  290. XmlSchemaDerivationMethod.Restriction | XmlSchemaDerivationMethod.Substitution;
  291. if(block == XmlSchemaDerivationMethod.All)
  292. blockResolved = allblock;
  293. else if(block == XmlSchemaDerivationMethod.None)
  294. blockResolved = allblock;
  295. else
  296. {
  297. if((block & ~allblock) != 0)
  298. warn(h,"Some of the values for block are invalid in this context");
  299. blockResolved = block & allblock;
  300. }
  301. if(schemaType != null && schemaTypeName != null && !schemaTypeName.IsEmpty)
  302. {
  303. error(h,"both schemaType and content can't be present");
  304. }
  305. //Even if both are present, read both of them.
  306. if(schemaType != null)
  307. {
  308. if(schemaType is XmlSchemaSimpleType)
  309. {
  310. errorCount += ((XmlSchemaSimpleType)schemaType).Compile(h,schema);
  311. }
  312. else if(schemaType is XmlSchemaComplexType)
  313. {
  314. errorCount += ((XmlSchemaComplexType)schemaType).Compile(h,schema);
  315. }
  316. else
  317. error(h,"only simpletype or complextype is allowed");
  318. }
  319. if(schemaTypeName != null && !schemaTypeName.IsEmpty)
  320. {
  321. if(!XmlSchemaUtil.CheckQName(SchemaTypeName))
  322. error(h,"SchemaTypeName must be an XmlQualifiedName");
  323. }
  324. if(SubstitutionGroup != null && !SubstitutionGroup.IsEmpty)
  325. {
  326. if(!XmlSchemaUtil.CheckQName(SubstitutionGroup))
  327. error(h,"SubstitutionGroup must be a valid XmlQualifiedName");
  328. }
  329. foreach(XmlSchemaObject obj in constraints)
  330. {
  331. if(obj is XmlSchemaUnique)
  332. errorCount += ((XmlSchemaUnique)obj).Compile(h,schema);
  333. else if(obj is XmlSchemaKey)
  334. errorCount += ((XmlSchemaKey)obj).Compile(h,schema);
  335. else if(obj is XmlSchemaKeyref)
  336. errorCount += ((XmlSchemaKeyref)obj).Compile(h,schema);
  337. }
  338. }
  339. else
  340. {
  341. if(!XmlSchemaUtil.CheckQName(RefName))
  342. error(h,"RefName must be a XmlQualifiedName");
  343. if(name != null)
  344. error(h,"name must not be present when ref is present");
  345. if(Constraints.Count != 0)
  346. error(h,"key, keyref and unique must be absent");
  347. if(isNillable)
  348. error(h,"nillable must be absent");
  349. if(defaultValue != null)
  350. error(h,"default must be absent");
  351. if(fixedValue != null)
  352. error(h,"fixed must be null");
  353. if(form != XmlSchemaForm.None)
  354. error(h,"form must be absent");
  355. if(block != XmlSchemaDerivationMethod.None)
  356. error(h,"block must be absent");
  357. if(schemaTypeName != null && !schemaTypeName.IsEmpty)
  358. error(h,"type must be absent");
  359. if(SchemaType != null)
  360. error(h,"simpleType or complexType must be absent");
  361. qName = RefName;
  362. schema.MissingElementTypeRefs.Add (this);
  363. }
  364. }
  365. // PSVI contribution for XmlSchemaElement
  366. if(refName == null || RefName.IsEmpty) {
  367. if (this.schemaType != null)
  368. this.elementType = schemaType;
  369. else {
  370. XmlSchemaType xsType = null;
  371. if (schemaTypeName.Namespace == XmlSchema.Namespace)
  372. this.elementType = XmlSchemaDatatype.FromName (schemaTypeName);
  373. else if (schemaTypeName == XmlQualifiedName.Empty)
  374. elementType = XmlSchemaComplexType.AnyType;
  375. else
  376. schema.MissingElementTypeRefs.Add (this);
  377. }
  378. }
  379. XmlSchemaUtil.CompileID(Id,this,schema.IDCollection,h);
  380. this.CompilationId = schema.CompilationId;
  381. return errorCount;
  382. }
  383. internal void SetSchemaType (object type)
  384. {
  385. this.elementType = type;
  386. }
  387. [MonoTODO]
  388. internal int Validate(ValidationEventHandler h)
  389. {
  390. return errorCount;
  391. }
  392. //<element
  393. // abstract = boolean : false
  394. // block = (#all | List of (extension | restriction | substitution))
  395. // default = string
  396. // final = (#all | List of (extension | restriction))
  397. // fixed = string
  398. // form = (qualified | unqualified)
  399. // id = ID
  400. // maxOccurs = (nonNegativeInteger | unbounded) : 1
  401. // minOccurs = nonNegativeInteger : 1
  402. // name = NCName
  403. // nillable = boolean : false
  404. // ref = QName
  405. // substitutionGroup = QName
  406. // type = QName
  407. // {any attributes with non-schema namespace . . .}>
  408. // Content: (annotation?, ((simpleType | complexType)?, (unique | key | keyref)*))
  409. //</element>
  410. internal static XmlSchemaElement Read(XmlSchemaReader reader, ValidationEventHandler h)
  411. {
  412. XmlSchemaElement element = new XmlSchemaElement();
  413. Exception innerex;
  414. reader.MoveToElement();
  415. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
  416. {
  417. error(h,"Should not happen :1: XmlSchemaElement.Read, name="+reader.Name,null);
  418. reader.Skip();
  419. return null;
  420. }
  421. element.LineNumber = reader.LineNumber;
  422. element.LinePosition = reader.LinePosition;
  423. element.SourceUri = reader.BaseURI;
  424. while(reader.MoveToNextAttribute())
  425. {
  426. if(reader.Name == "abstract")
  427. {
  428. element.IsAbstract = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
  429. if(innerex != null)
  430. error(h,reader.Value + " is invalid value for abstract",innerex);
  431. }
  432. else if(reader.Name == "block")
  433. {
  434. element.block = XmlSchemaUtil.ReadDerivationAttribute(reader,out innerex, "block");
  435. if(innerex != null)
  436. warn(h,"some invalid values for block attribute were found",innerex);
  437. }
  438. else if(reader.Name == "default")
  439. {
  440. element.defaultValue = reader.Value;
  441. }
  442. else if(reader.Name == "final")
  443. {
  444. element.Final = XmlSchemaUtil.ReadDerivationAttribute(reader,out innerex, "block");
  445. if(innerex != null)
  446. warn(h,"some invalid values for final attribute were found",innerex);
  447. }
  448. else if(reader.Name == "fixed")
  449. {
  450. element.fixedValue = reader.Value;
  451. }
  452. else if(reader.Name == "form")
  453. {
  454. element.form = XmlSchemaUtil.ReadFormAttribute(reader,out innerex);
  455. if(innerex != null)
  456. error(h,reader.Value + " is an invalid value for form attribute",innerex);
  457. }
  458. else if(reader.Name == "id")
  459. {
  460. element.Id = reader.Value;
  461. }
  462. else if(reader.Name == "maxOccurs")
  463. {
  464. try
  465. {
  466. element.MaxOccursString = reader.Value;
  467. }
  468. catch(Exception e)
  469. {
  470. error(h,reader.Value + " is an invalid value for maxOccurs",e);
  471. }
  472. }
  473. else if(reader.Name == "minOccurs")
  474. {
  475. try
  476. {
  477. element.MinOccursString = reader.Value;
  478. }
  479. catch(Exception e)
  480. {
  481. error(h,reader.Value + " is an invalid value for minOccurs",e);
  482. }
  483. }
  484. else if(reader.Name == "name")
  485. {
  486. element.Name = reader.Value;
  487. }
  488. else if(reader.Name == "nillable")
  489. {
  490. element.IsNillable = XmlSchemaUtil.ReadBoolAttribute(reader,out innerex);
  491. if(innerex != null)
  492. error(h,reader.Value + "is not a valid value for nillable",innerex);
  493. }
  494. else if(reader.Name == "ref")
  495. {
  496. element.refName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  497. if(innerex != null)
  498. error(h, reader.Value + " is not a valid value for ref attribute",innerex);
  499. }
  500. else if(reader.Name == "substitutionGroup")
  501. {
  502. element.substitutionGroup = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  503. if(innerex != null)
  504. error(h, reader.Value + " is not a valid value for substitutionGroup attribute",innerex);
  505. }
  506. else if(reader.Name == "type")
  507. {
  508. element.SchemaTypeName = XmlSchemaUtil.ReadQNameAttribute(reader,out innerex);
  509. if(innerex != null)
  510. error(h, reader.Value + " is not a valid value for type attribute",innerex);
  511. }
  512. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  513. {
  514. error(h,reader.Name + " is not a valid attribute for element",null);
  515. }
  516. else
  517. {
  518. XmlSchemaUtil.ReadUnhandledAttribute(reader,element);
  519. }
  520. }
  521. reader.MoveToElement();
  522. if(reader.IsEmptyElement)
  523. return element;
  524. // Content: annotation?,
  525. // (simpleType | complexType)?,
  526. // (unique | key | keyref)*
  527. int level = 1;
  528. while(reader.ReadNextElement())
  529. {
  530. if(reader.NodeType == XmlNodeType.EndElement)
  531. {
  532. if(reader.LocalName != xmlname)
  533. error(h,"Should not happen :2: XmlSchemaElement.Read, name="+reader.Name,null);
  534. break;
  535. }
  536. if(level <= 1 && reader.LocalName == "annotation")
  537. {
  538. level = 2; //Only one annotation
  539. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  540. if(annotation != null)
  541. element.Annotation = annotation;
  542. continue;
  543. }
  544. if(level <= 2)
  545. {
  546. if(reader.LocalName == "simpleType")
  547. {
  548. level = 3;
  549. XmlSchemaSimpleType simple = XmlSchemaSimpleType.Read(reader,h);
  550. if(simple != null)
  551. element.SchemaType = simple;
  552. continue;
  553. }
  554. if(reader.LocalName == "complexType")
  555. {
  556. level = 3;
  557. XmlSchemaComplexType complex = XmlSchemaComplexType.Read(reader,h);
  558. if(complex != null)
  559. {
  560. element.SchemaType = complex;
  561. }
  562. continue;
  563. }
  564. }
  565. if(level <= 3)
  566. {
  567. if(reader.LocalName == "unique")
  568. {
  569. level = 3;
  570. XmlSchemaUnique unique = XmlSchemaUnique.Read(reader,h);
  571. if(unique != null)
  572. element.constraints.Add(unique);
  573. continue;
  574. }
  575. else if(reader.LocalName == "key")
  576. {
  577. level = 3;
  578. XmlSchemaKey key = XmlSchemaKey.Read(reader,h);
  579. if(key != null)
  580. element.constraints.Add(key);
  581. continue;
  582. }
  583. else if(reader.LocalName == "keyref")
  584. {
  585. level = 3;
  586. XmlSchemaKeyref keyref = XmlSchemaKeyref.Read(reader,h);
  587. if(keyref != null)
  588. element.constraints.Add(keyref);
  589. continue;
  590. }
  591. }
  592. reader.RaiseInvalidElementError();
  593. }
  594. return element;
  595. }
  596. }
  597. }