1
votes

In my project, I have to generate thesaurus file for SharePoint Search structure. If I edit the current thesaurus file (tseng.xml), there is no problem for Synonym search in SharePoint Search Center.

However, I get the synonyms from List and I need to push them into tseng.xml file in an approriate structure. I achieved this process but generated structure(in tseng.xml) doesn't work in SharePoint Search.

I read that article (link) about this topic, the assumption is that parsing problem in my thesaurus generation code. He used XmlWriter to generate xml.

And now, I need to use LINQ to XML and how can I generate thesaurus file using linq and create approriate xml structure for thesaurus?

Thanks.

1

1 Answers

0
votes

You can use LINQ to XML in conjunction with an XmlWriter. Build your XDocument and then save using XDocument.Save Method (XmlWriter):

StringBuilder sb = new StringBuilder();
XmlWriterSettings xws = new XmlWriterSettings();
xws.OmitXmlDeclaration = true;
xws.Indent = true;

using (XmlWriter xw = XmlWriter.Create(sb, xws)) {
    XDocument doc = new XDocument(
    new XElement("Child",
        new XElement("GrandChild", "some content")
    )
    );
    doc.Save(xw);
}

Console.WriteLine(sb.ToString());