2012-01-25 123 views
1

在我的项目中,我必须生成SharePoint搜索结构的同义词库文件。如果我编辑当前同义词库文件(tseng.xml),则SharePoint搜索中心中的同义词搜索没有任何问题。从SharePoint列表生成自定义SharePoint同义词库文件

但是,我从列表中获得同义词,我需要将它们推送到适当结构中的tseng.xml文件中。我实现了此过程,但生成的结构(在tseng.xml中)在SharePoint搜索中无效。

我读过关于这个话题的那篇文章(link),这个假设是在我的词库生成代码中解析问题。他使用XmlWriter生成XML。

现在,我需要使用LINQ to XML以及如何使用linq生成同义词库文件并为同义词库创建适当的xml结构?

谢谢。

回答

0

您可以将LINQ to XML与XmlWriter结合使用。构建您的XDocument,然后使用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());