/// <param name="pos">找到Tag之后,Tag的起始位置</param> public static XTag FindTag(string tagName, string text, ref int pos) { Regex reg1 = new Regex("<" + tagName + "[^a-zA-Z]"); Regex reg2 = new Regex("<" + tagName + ".*?>"); Match m1 = reg1.Match(text, pos); if (m1.Success) { Match m2 = reg2.Match(text, m1.Index); XTag tag = new XTag(m2.Value); pos = m2.Index; return(tag); } return(null); }
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); }