xelementspwebspsite

Extracting SPWeb.Groups.Xml in XElement


I need to get SPWeb.Groups.Xml in XElement to create XDocument.

      SPSite site = new SPSite(url);
        foreach (SPWeb web in site.AllWebs)
        {
            SPUserCollection spusers = site.RootWeb.SiteUsers;
            XElement xeGroup = new XElement("Groups");
            xeGroup =  new XElement(web.Groups.Xml);} 

currently I am getting error as "The '<' character, hexadecimal value 0x3C, cannot be included in a name.",

Please suggest workaround or correct way to retrieve the information.

Thanks for your help.


Solution

  • My solution, not very elegant...

    SPSite site = new SPSite(url);
        foreach (SPWeb web in site.AllWebs)
        {
                XElement xeGroup = new XElement("Groups");
                xd.LoadXml(web.Groups.Xml);
                xeGroup = XElement.Load(new XmlNodeReader(xd));