2016-05-30 4 views
0

私は、Apache NetBeansアプリケーションでApache Solrを使用します。今私は自分のアプリケーションからSolrのelevate.xmlファイルで正しいqueryタグを使いたいと思う。 elevate.xmlファイルのMVCアプリケーションから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はありますか?

+0

含むをuがこの同じXMLファイルに新しいタグを追加しますか? using c# –

+0

はい、既に2つのクエリタグがあります。私は他のクエリタグを追加したい。 – Ankita

+0

これはどのように新しいXMLファイルですか? –

答えて

1

はこの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試してみてください - > [ファイル名のパスと拡張子(.xmlファイル)

+0

あなたのお返事ありがとうございます。私はこれを試してみます – Ankita

+0

雅確か@アンキ –

+0

ありがとうDinesh、それは動作します。さらに、属性とその値を追加するためにいくつかの行を追加しました。 – Ankita

関連する問題