XmlSchemaXPath.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Author: Dwivedi, Ajay kumar
  2. // [email protected]
  3. using System;
  4. using System.Xml.Serialization;
  5. using System.ComponentModel;
  6. using System.Xml;
  7. namespace System.Xml.Schema
  8. {
  9. /// <summary>
  10. /// Summary description for XmlSchemaXPath.
  11. /// </summary>
  12. public class XmlSchemaXPath : XmlSchemaAnnotated
  13. {
  14. private string xpath;
  15. public XmlSchemaXPath()
  16. {
  17. }
  18. [DefaultValue(null)]
  19. [System.Xml.Serialization.XmlAttribute("xpath")]
  20. public string XPath
  21. {
  22. get{ return xpath; }
  23. set{ xpath = value; }
  24. }
  25. internal int Compile(ValidationEventHandler h, XmlSchema schema)
  26. {
  27. // If this is already compiled this time, simply skip.
  28. if (this.IsComplied (schema.CompilationId))
  29. return 0;
  30. XmlSchemaUtil.CompileID(Id, this, schema.IDCollection, h);
  31. this.CompilationId = schema.CompilationId;
  32. return errorCount;
  33. }
  34. //<selector
  35. // id = ID
  36. // xpath = a subset of XPath expression, see below
  37. // {any attributes with non-schema namespace . . .}>
  38. // Content: (annotation?)
  39. //</selector>
  40. internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h,string name)
  41. {
  42. XmlSchemaXPath path = new XmlSchemaXPath();
  43. reader.MoveToElement();
  44. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != name)
  45. {
  46. error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
  47. reader.Skip();
  48. return null;
  49. }
  50. path.LineNumber = reader.LineNumber;
  51. path.LinePosition = reader.LinePosition;
  52. path.SourceUri = reader.BaseURI;
  53. while(reader.MoveToNextAttribute())
  54. {
  55. if(reader.Name == "id")
  56. {
  57. path.Id = reader.Value;
  58. }
  59. else if(reader.Name == "xpath")
  60. {
  61. path.xpath = reader.Value;
  62. }
  63. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  64. {
  65. error(h,reader.Name + " is not a valid attribute for "+name,null);
  66. }
  67. else
  68. {
  69. XmlSchemaUtil.ReadUnhandledAttribute(reader,path);
  70. }
  71. }
  72. reader.MoveToElement();
  73. if(reader.IsEmptyElement)
  74. return path;
  75. // Content: (annotation?)
  76. int level = 1;
  77. while(reader.ReadNextElement())
  78. {
  79. if(reader.NodeType == XmlNodeType.EndElement)
  80. {
  81. if(reader.LocalName != name)
  82. error(h,"Should not happen :2: XmlSchemaXPath.Read, name="+reader.Name,null);
  83. break;
  84. }
  85. if(level <= 1 && reader.LocalName == "annotation")
  86. {
  87. level = 2; //Only one annotation
  88. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  89. if(annotation != null)
  90. path.Annotation = annotation;
  91. continue;
  92. }
  93. reader.RaiseInvalidElementError();
  94. }
  95. return path;
  96. }
  97. }
  98. }