获取XML的根节点名称

private static Regex regex = new Regex("<(\\w+?)[ >]", RegexOptions.Compiled); 
private string GetRootElement(string body)
{
    Match match = regex.Match(body);
        if (match.Success)
        {
            return match.Groups[1].ToString();
        }
        else
        {
            throw new TopException("Invalid XML response format!");
        }
}

 

posted @ 2013-04-03 15:02  xust  阅读(598)  评论(0编辑  收藏  举报