Beispiel #1
0
 public void AddRule(string pattern, Rule rule)
 {
     rule.Digester = this;
     Rules.Add(pattern, rule);
 }
Beispiel #2
0
 public object Parse(XmlReader reader)
 {
     this.reader = reader;
     while (reader.Read())
     {
         if (reader.NodeType == XmlNodeType.Element)
         {
             bool flag;
             if (!(flag = reader.IsEmptyElement))
             {
                 bodies.Push(new StringBuilder());
             }
             else
             {
                 body = null;
             }
             StringBuilder builder = new StringBuilder(match);
             if (match.Length > 0)
             {
                 builder.Append("/");
             }
             if ((reader.LocalName != null) && (reader.LocalName.Length <= 1))
             {
                 builder.Append(reader.LocalName);
             }
             else
             {
                 builder.Append(reader.Name);
             }
             match = builder.ToString();
             string namespaceURI = reader.NamespaceURI;
             attributes.Clear();
             while (reader.MoveToNextAttribute())
             {
                 attributes[reader.Name] = reader.Value;
             }
             IList <Rule> list = Rules.Match(namespaceURI, match);
             if ((list != null) && (list.Count > 0))
             {
                 foreach (Rule rule in list)
                 {
                     rule.OnBegin();
                 }
             }
             if (flag)
             {
                 if (list != null)
                 {
                     for (int i = list.Count - 1; i >= 0; i--)
                     {
                         list[i].OnEnd();
                     }
                 }
                 int length = match.LastIndexOf("/");
                 if (length >= 0)
                 {
                     match = match.Substring(0, length);
                 }
                 else
                 {
                     match = "";
                 }
             }
         }
         if ((reader.NodeType == XmlNodeType.Text) || (reader.NodeType == XmlNodeType.CDATA))
         {
             bodies.Peek().Append(reader.Value);
         }
         if (reader.NodeType == XmlNodeType.EndElement)
         {
             body = bodies.Pop().ToString();
             IList <Rule> list2 = null;
             if (body != null)
             {
                 list2 = Rules.Match(reader.NamespaceURI, match);
                 if ((list2 != null) && (list2.Count > 0))
                 {
                     foreach (Rule rule3 in list2)
                     {
                         rule3.OnBody();
                     }
                 }
             }
             if (list2 != null)
             {
                 for (int j = list2.Count - 1; j >= 0; j--)
                 {
                     list2[j].OnEnd();
                 }
             }
             int num2 = match.LastIndexOf("/");
             if (num2 >= 0)
             {
                 match = match.Substring(0, num2);
             }
             else
             {
                 match = "";
             }
         }
     }
     while (Depth > 1)
     {
         Pop();
     }
     foreach (Rule rule2 in Rules.GetRules())
     {
         rule2.OnFinish();
     }
     Clear();
     return(root);
 }