从MVC应用程序写入elevate.xml文件

时间:2016-05-30 04:24:01

标签: xml asp.net-mvc solr

我使用Apache Solr和Dot Net MVC应用程序。现在我想从我的应用程序中查找Solr的elevate.xml文件中的查询标记。

elevate.xml文件的结构如下:

<elevate>
  <query text="foo bar">
    <doc id="1" />
    <doc id="2" />
    <doc id="3" />
  </query>

  <query text="ipod">
    <doc id="MA147LL/A" />  <!-- put the actual ipod at the top -->
    <doc id="IW-02" exclude="true" /> <!-- exclude this cable -->
  </query>
</elevate>

我想添加其他查询标记的方式相同。我该怎么做?有没有可用的API来编写它?

1 个答案:

答案 0 :(得分:1)

试试这个

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strFilename);
XmlElement elmRoot = xmlDoc.DocumentElement;
XmlElement elmNew = xmlDoc.CreateElement("Query");
XmlAttribute attribute = xmlDoc.CreateAttribute("text"); //attribute of  query tag
attribute.Value = "foo bar";
elmNew.Attributes.Append(attribute);
elmRoot.AppendChild(elmNew);
xmlDoc.Save(strFilename);

strFilename - &gt;您的文件名包括路径和扩展名(.xml)