示例#1
0
文件: Model.cs 项目: klyuchnikov/Seti
 public Attribute(Tag tag, string name, string value)
 {
     this.ID = Count++;
     this.Name = name;
     this.Value = value;
     this.Tag = tag;
 }
示例#2
0
 /// <summary>
 /// Разбор тегов
 /// </summary>
 /// <param name="str">документ</param>
 /// <param name="doc">объектная модель докумнета</param>
 /// <param name="pattern">шаблон разбора</param>
 private static void ParseTags(string str, Document doc, string pattern)
 {
     var matches = Regex.Matches(str, String.Format("<{0}\\s*(?<attr>.*?)>(?<value>[\\d\\D]*?)</(?<tag>{0})>", pattern), RegexOptions.IgnoreCase);
     foreach (Match h in matches)
     {
         var tagS = h.Groups["tag"].Value;
         var value = h.Groups["value"].Value.Replace("\n", "").Replace("\r", "");
         var tag = new Tag(doc, tagS, value);
         ParseAttributes(tag, h.Groups["attr"].Value);
         Model.Current.Tags.Add(tag);
     }
 }
示例#3
0
 /// <summary>
 /// Разбор тегов
 /// </summary>
 /// <param name="str">документ</param>
 /// <param name="doc">объектная модель докумнета</param>
 /// <param name="pattern">шаблон разбора</param>
 private static void ParseTagsWhitoutBody(string str, Document doc, string pattern)
 {
     var matches = Regex.Matches(str, String.Format("<(?<tag>{0})\\s*(?<attr>.*?)/>", pattern), RegexOptions.IgnoreCase);
     foreach (Match h in matches)
     {
         var tagS = h.Groups["tag"].Value;
         var tag = new Tag(doc, tagS, null);
         ParseAttributes(tag, h.Groups["attr"].Value);
         Model.Current.Tags.Add(tag);
     }
 }
示例#4
0
 /// <summary>
 /// Разбор аттрибутов
 /// </summary>
 /// <param name="tag">объектная модель тега</param>
 /// <param name="str">документ</param>
 private static void ParseAttributes(Tag tag, string str)
 {
     var attrsS = str.Replace("\n", "").Replace("\r", "");
     var ms = Regex.Matches(attrsS, "\\s*?(?<name>\\S*?)=\"(?<value>.*?)\"", RegexOptions.IgnoreCase);
     foreach (var newatt in from Match m in ms
                            let name = m.Groups["name"].Value
                            let valueA = m.Groups["value"].Value
                            select new Attribute(tag, name, valueA))
     {
         Model.Current.Attributes.Add(newatt);
     }
 }