XmlSchemaXPath.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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, XmlSchemaInfo info)
  26. {
  27. XmlSchemaUtil.CompileID(Id, this, info.IDCollection, h);
  28. return errorCount;
  29. }
  30. //<selector
  31. // id = ID
  32. // xpath = a subset of XPath expression, see below
  33. // {any attributes with non-schema namespace . . .}>
  34. // Content: (annotation?)
  35. //</selector>
  36. internal static XmlSchemaXPath Read(XmlSchemaReader reader, ValidationEventHandler h,string name)
  37. {
  38. XmlSchemaXPath path = new XmlSchemaXPath();
  39. reader.MoveToElement();
  40. if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != name)
  41. {
  42. error(h,"Should not happen :1: XmlSchemaComplexContentRestriction.Read, name="+reader.Name,null);
  43. reader.Skip();
  44. return null;
  45. }
  46. path.LineNumber = reader.LineNumber;
  47. path.LinePosition = reader.LinePosition;
  48. path.SourceUri = reader.BaseURI;
  49. while(reader.MoveToNextAttribute())
  50. {
  51. if(reader.Name == "id")
  52. {
  53. path.Id = reader.Value;
  54. }
  55. else if(reader.Name == "xpath")
  56. {
  57. path.xpath = reader.Value;
  58. }
  59. else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
  60. {
  61. error(h,reader.Name + " is not a valid attribute for "+name,null);
  62. }
  63. else
  64. {
  65. XmlSchemaUtil.ReadUnhandledAttribute(reader,path);
  66. }
  67. }
  68. reader.MoveToElement();
  69. if(reader.IsEmptyElement)
  70. return path;
  71. // Content: (annotation?)
  72. int level = 1;
  73. while(reader.ReadNextElement())
  74. {
  75. if(reader.NodeType == XmlNodeType.EndElement)
  76. {
  77. if(reader.LocalName != name)
  78. error(h,"Should not happen :2: XmlSchemaXPath.Read, name="+reader.Name,null);
  79. break;
  80. }
  81. if(level <= 1 && reader.LocalName == "annotation")
  82. {
  83. level = 2; //Only one annotation
  84. XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
  85. if(annotation != null)
  86. path.Annotation = annotation;
  87. continue;
  88. }
  89. reader.RaiseInvalidElementError();
  90. }
  91. return path;
  92. }
  93. }
  94. }