コード例 #1
0
 public XELement(XFragment frag, int start)
 {
     doc        = frag;
     this.start = start;
     for (int i = start + 1; i < doc.parts.Count; i++)
     {
         if (doc.parts[i].type == PartType.tag_start)
         {
             XELement ele = new XELement(doc, i);
             ele.parent = this;
             childs.Add(ele);
             i = ele.end + 1;
         }
         if (doc.parts[i].type == PartType.tag_end)
         {
             if (((XTag)doc.parts[i]).tagname == ((XTag)doc.parts[start]).tagname)
             {
                 end = i; break;
             }
             else
             {
                 Log.log("Error:dismatched end tag");
             }
         }
     }
     if (end == -1)
     {
         Log.log("Error:Closing Tag Failure.");
     }
 }
コード例 #2
0
        public XFragment(string text, int start)
        {
            Regex reg_tag = new Regex("<.*?>");
            int   count = 0, pos = start;
            Match m;

            do
            {
                m = reg_tag.Match(text, pos);
                if (!m.Success)
                {
                    Log.log("Error:Unexpect end."); return;
                }
                XTag tag = new XTag(m.Value);
                if (tag.type == PartType.tag_start)
                {
                    count++;
                }
                if (tag.type == PartType.tag_end)
                {
                    count--;
                }
                if (m.Index > pos)
                {
                    parts.Add(new XText(text.Substring(pos, m.Index - pos)));
                }
                parts.Add(tag);
                pos = m.Index + m.Value.Length;
            }while (count > 0);
            Length = m.Index - start + m.Value.Length;
            root   = new XELement(this, 0);
        }