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

安基塔

我将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编写它?

迪内什·J

试试这个

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->您的文件名,包括路径和扩展名(.xml)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章