示例#1
0
 public XsdIdentityPath SelectorMatches(ArrayList qnameStack, int depth)
 {
     for (int i = 0; i < this.Selector.Paths.Length; i++)
     {
         XsdIdentityPath xsdIdentityPath = this.Selector.Paths[i];
         if (depth == this.StartDepth)
         {
             if (xsdIdentityPath.OrderedSteps.Length == 0)
             {
                 return(xsdIdentityPath);
             }
         }
         else if (depth - this.StartDepth >= xsdIdentityPath.OrderedSteps.Length - 1)
         {
             int num = xsdIdentityPath.OrderedSteps.Length;
             if (xsdIdentityPath.OrderedSteps[num - 1].IsAttribute)
             {
                 num--;
             }
             if (!xsdIdentityPath.Descendants || depth >= this.StartDepth + num)
             {
                 if (xsdIdentityPath.Descendants || depth == this.StartDepth + num)
                 {
                     num--;
                     int num2 = 0;
                     while (0 <= num)
                     {
                         XsdIdentityStep xsdIdentityStep = xsdIdentityPath.OrderedSteps[num];
                         if (!xsdIdentityStep.IsAnyName)
                         {
                             XmlQualifiedName xmlQualifiedName = (XmlQualifiedName)qnameStack[qnameStack.Count - num2 - 1];
                             if (xsdIdentityStep.NsName == null || !(xmlQualifiedName.Namespace == xsdIdentityStep.NsName))
                             {
                                 if (!(xsdIdentityStep.Name == xmlQualifiedName.Name) || !(xsdIdentityStep.Namespace == xmlQualifiedName.Namespace))
                                 {
                                     if (this.alwaysTrue)
                                     {
                                         break;
                                     }
                                 }
                             }
                         }
                         num2++;
                         num--;
                     }
                     if (num < 0)
                     {
                         return(xsdIdentityPath);
                     }
                 }
             }
         }
     }
     return(null);
 }
示例#2
0
		private void ParseStep (string xpath, int pos, ArrayList steps,
			ArrayList paths, ValidationEventHandler h, XmlSchema schema)
		{
			pos = SkipWhitespace (xpath, pos);
			if (xpath.Length == pos) {
				error (h, "Empty xpath expression is specified");
				return;
			}

			XsdIdentityStep step = new XsdIdentityStep ();
			switch (xpath [pos]) {
			case '@':
				if (isSelector) {
					error (h, "Selector cannot include attribute axes.");
					currentPath = null;
					return;
				}
				pos++;
				step.IsAttribute = true;
				pos = SkipWhitespace (xpath, pos);
				if (xpath.Length > pos && xpath [pos] == '*') {
					pos++;
					step.IsAnyName = true;
					break;
				}
				goto default;
			case '.':
				pos++;	// do nothing ;-)
				step.IsCurrent = true;
				break;
			case '*':
				pos++;
				step.IsAnyName = true;
				break;
			case 'c':
				if (xpath.Length > pos + 5 && xpath.IndexOf ("child", pos, 5) == pos) {
					int tmp = pos;
					pos += 5;
					pos = SkipWhitespace (xpath, pos);
					if (xpath.Length > pos && xpath [pos] == ':' && xpath [pos+1] == ':') {
						pos += 2;
						if (xpath.Length > pos && xpath [pos] == '*') {
							pos++;
							step.IsAnyName = true;
							break;
						}
						pos = SkipWhitespace (xpath, pos);
					}
					else
						pos = tmp;
				}
				goto default;
			case 'a':
				if (xpath.Length > pos + 9 && xpath.IndexOf ("attribute", pos, 9) == pos) {
					int tmp = pos;
					pos += 9;
					pos = SkipWhitespace (xpath, pos);
					if (xpath.Length > pos && xpath [pos] == ':' && xpath [pos+1] == ':') {
						if (isSelector) {
							error (h, "Selector cannot include attribute axes.");
							currentPath = null;
							return;
						}
						pos += 2;
						step.IsAttribute = true;
						if (xpath.Length > pos && xpath [pos] == '*') {
							pos++;
							step.IsAnyName = true;
							break;
						}
						pos = SkipWhitespace (xpath, pos);
					}
					else
						pos = tmp;
				}
				goto default;
			default:
				int nameStart = pos;
				while (xpath.Length > pos) {
					if (!XmlChar.IsNCNameChar (xpath [pos]))
						break;
					else
						pos++;
				}
				if (pos == nameStart) {
					error (h, "Invalid path format for a field.");
					this.currentPath = null;
					return;
				}
				if (xpath.Length == pos || xpath [pos] != ':')
					step.Name = xpath.Substring (nameStart, pos - nameStart);
				else {
					string prefix = xpath.Substring (nameStart, pos - nameStart);
					pos++;
					if (xpath.Length > pos && xpath [pos] == '*') {
						string ns = nsmgr.LookupNamespace (prefix, false);
						if (ns == null) {
							error (h, "Specified prefix '" + prefix + "' is not declared.");
							this.currentPath = null;
							return;
						}
						step.NsName = ns;
						pos++;
					} else {
						int localNameStart = pos;
						while (xpath.Length > pos) {
							if (!XmlChar.IsNCNameChar (xpath [pos]))
								break;
							else
								pos++;
						}
						step.Name = xpath.Substring (localNameStart, pos - localNameStart);
						string ns = nsmgr.LookupNamespace (prefix, false);
						if (ns == null) {
							error (h, "Specified prefix '" + prefix + "' is not declared.");
							this.currentPath = null;
							return;
						}
						step.Namespace = ns;
					}
				}
				break;
			}
			if (!step.IsCurrent)	// Current step is meaningless, other than its representation.
				steps.Add (step);
			pos = SkipWhitespace (xpath, pos);
			if (xpath.Length == pos) {
				currentPath.OrderedSteps = (XsdIdentityStep []) steps.ToArray (typeof (XsdIdentityStep));
				paths.Add (currentPath);
				return;
			}
			else if (xpath [pos] == '/') {
				pos++;
				if (step.IsAttribute) {
					error (h, "Unexpected xpath token after Attribute NameTest.");
					this.currentPath = null;
					return;
				}
				this.ParseStep (xpath, pos, steps, paths, h, schema);
				if (currentPath == null) // For ValidationEventHandler
					return;
				currentPath.OrderedSteps = (XsdIdentityStep []) steps.ToArray (typeof (XsdIdentityStep));
			} else if (xpath [pos] == '|') {
				pos++;
				currentPath.OrderedSteps = (XsdIdentityStep []) steps.ToArray (typeof (XsdIdentityStep));
				paths.Add (this.currentPath);
				this.currentPath = new XsdIdentityPath ();
				this.ParsePath (xpath, pos, paths, h, schema);
			} else {
				error (h, "Unexpected xpath token after NameTest.");
				this.currentPath = null;
				return;
			}
		}
        internal XsdIdentityPath Matches(bool matchesAttr, object sender, XmlNameTable nameTable, ArrayList qnameStack, string sourceUri, object schemaType, IXmlNamespaceResolver nsResolver, IXmlLineInfo lineInfo, int depth, string attrName, string attrNS, object attrValue)
        {
            XsdIdentityPath xsdIdentityPath = null;

            for (int i = 0; i < this.field.Paths.Length; i++)
            {
                XsdIdentityPath xsdIdentityPath2 = this.field.Paths[i];
                bool            isAttribute      = xsdIdentityPath2.IsAttribute;
                if (matchesAttr == isAttribute)
                {
                    if (xsdIdentityPath2.IsAttribute)
                    {
                        XsdIdentityStep xsdIdentityStep = xsdIdentityPath2.OrderedSteps[xsdIdentityPath2.OrderedSteps.Length - 1];
                        bool            flag            = false;
                        if (xsdIdentityStep.IsAnyName || xsdIdentityStep.NsName != null)
                        {
                            if (xsdIdentityStep.IsAnyName || attrNS == xsdIdentityStep.NsName)
                            {
                                flag = true;
                            }
                        }
                        else if (xsdIdentityStep.Name == attrName && xsdIdentityStep.Namespace == attrNS)
                        {
                            flag = true;
                        }
                        if (!flag)
                        {
                            goto IL_2AF;
                        }
                        if (this.entry.StartDepth + (xsdIdentityPath2.OrderedSteps.Length - 1) != depth - 1)
                        {
                            goto IL_2AF;
                        }
                        xsdIdentityPath = xsdIdentityPath2;
                    }
                    if (!this.FieldFound || depth <= this.FieldFoundDepth || this.FieldFoundPath != xsdIdentityPath2)
                    {
                        if (xsdIdentityPath2.OrderedSteps.Length == 0)
                        {
                            if (depth == this.entry.StartDepth)
                            {
                                return(xsdIdentityPath2);
                            }
                        }
                        else if (depth - this.entry.StartDepth >= xsdIdentityPath2.OrderedSteps.Length - 1)
                        {
                            int j = xsdIdentityPath2.OrderedSteps.Length;
                            if (isAttribute)
                            {
                                j--;
                            }
                            if (!xsdIdentityPath2.Descendants || depth >= this.entry.StartDepth + j)
                            {
                                if (xsdIdentityPath2.Descendants || depth == this.entry.StartDepth + j)
                                {
                                    for (j--; j >= 0; j--)
                                    {
                                        XsdIdentityStep xsdIdentityStep = xsdIdentityPath2.OrderedSteps[j];
                                        if (!xsdIdentityStep.IsCurrent && !xsdIdentityStep.IsAnyName)
                                        {
                                            XmlQualifiedName xmlQualifiedName = (XmlQualifiedName)qnameStack[this.entry.StartDepth + j + ((!isAttribute) ? 1 : 0)];
                                            if (xsdIdentityStep.NsName == null || !(xmlQualifiedName.Namespace == xsdIdentityStep.NsName))
                                            {
                                                if ((!(xsdIdentityStep.Name == "*") && !(xsdIdentityStep.Name == xmlQualifiedName.Name)) || !(xsdIdentityStep.Namespace == xmlQualifiedName.Namespace))
                                                {
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (j < 0)
                                    {
                                        if (!matchesAttr)
                                        {
                                            return(xsdIdentityPath2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                IL_2AF :;
            }
            if (xsdIdentityPath != null)
            {
                this.FillAttributeFieldValue(sender, nameTable, sourceUri, schemaType, nsResolver, attrValue, lineInfo, depth);
                if (this.Identity != null)
                {
                    return(xsdIdentityPath);
                }
            }
            return(null);
        }