/// <summary> /// </summary> public static string ProcessXml(string xml, Group tGroup, TreeNode curNode) { var retMsg = ""; XElement xTree = null; try { // load xml xTree = XElement.Load(new StringReader(xml)); } catch (Exception ex) { return(ex.Message); } foreach (var termSetElement in xTree.XPathSelectElements("/termset")) { string newTermSetName = GenUtil.MmdNormalize(GenUtil.SafeXmlAttributeToString(termSetElement, "name")); Guid newTermSetId = GenUtil.SafeXmlAttributeToGuid(termSetElement, "id"); bool newTermSetIsAvailForTagging = GenUtil.SafeXmlAttributeToBool(termSetElement, "isavailfortagging"); string newTermDescr = GenUtil.SafeXmlAttributeToString(termSetElement, "description"); bool newTermSetIsOpenForTermCreation = GenUtil.SafeXmlAttributeToBool(termSetElement, "isopenfortermcreation"); if (GenUtil.IsNull(newTermSetName)) { return("TermSet name is missing."); } // create termset (or update if found) TermSet tSet = null; try { tSet = tGroup.TermStore.GetTermSet(newTermSetId); if (tSet != null) { // termset found using guid tSet.Name = newTermSetName; tSet.Description = newTermDescr; tSet.IsAvailableForTagging = newTermSetIsAvailForTagging; tSet.IsOpenForTermCreation = newTermSetIsOpenForTermCreation; tSet.TermStore.CommitAll(); } else { tSet = tGroup.TermStore.GetTermSets(newTermSetName, CultureInfo.CurrentCulture.LCID).FirstOrDefault(); if (tSet != null) { // termset found using name tSet.Description = newTermDescr; tSet.IsAvailableForTagging = newTermSetIsAvailForTagging; tSet.IsOpenForTermCreation = newTermSetIsOpenForTermCreation; tSet.TermStore.CommitAll(); } else { tSet = tGroup.CreateTermSet(newTermSetName, newTermSetId, CultureInfo.CurrentCulture.LCID); tSet.Description = newTermDescr; tSet.IsAvailableForTagging = newTermSetIsAvailForTagging; tSet.IsOpenForTermCreation = newTermSetIsOpenForTermCreation; tSet.TermStore.CommitAll(); } } } catch (Exception ex) { return(ex.Message); } // create terms within (recursive) try { foreach (var termElement in termSetElement.XPathSelectElements("term")) { ProcessTerm(termElement, tSet, null); } } catch (Exception ex) { return(ex.Message); } } return(retMsg); }