public XFragment(string text, int start)
        {
            if (text[start] != '<')
            {
                throw new XMLException("XFragment Error:Unexpect Start.");
            }
            indexInSource = start;
            Regex reg_tag = new Regex("<[^\\!]*?>");
            int   count = 0, pos = start;
            Match m;

            do
            {
                m = reg_tag.Match(text, pos);
                if (!m.Success)
                {
                    new XMLException("XFragment Error:Unexpect end.");
                }
                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);
            originalLength = m.Index - start + m.Value.Length;
            root           = new XELement(this, 0);
        }
 public XELement(XFragment frag, int start)
 {
     doc = frag;
     this.tagStartRef = start;
     if (doc.parts[tagStartRef].type == PartType.tag_single)
     {
         this.tagEndRef = start;
         return;
     }
     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.tagEndRef;
             continue;
         }
         if (doc.parts[i].type == PartType.tag_end)
         {
             if (((XTag)doc.parts[i]).tagname == ((XTag)doc.parts[start]).tagname)
             {
                 tagEndRef = i; break;
             }
             else
             {
                 throw new XMLException("dismatched end tag:" + doc.parts[start] + "..." + doc.parts[i]);
             }
         }
     }
     if (tagEndRef == -1)
     {
         throw new XMLException("Failure when close tag.");
     }
 }