在asp.net节点中添加xml节点

本文关键字:节点 添加 xml net asp | 更新日期: 2023-09-27 18:16:40

请查看代码并建议我如何使用c#

我在字符串变量

下面有节点
 <state_tax_pin>d</state_tax_pin> 
<loan_amount>139397.0000</loan_amount>
<note_date>2009-07-27T00:00:00+05:30</note_date>
<orig_rec_date>2015-09-02T00:00:00+05:30</orig_rec_date>
<recording_information>sdf</recording_information>
<address>address</address>

我正在尝试转换为以下格式

<state_tax_pin></state_tax_pin>
   <original_terms>
       <loan_amount>645000</loan_amount>
       <note_date>2002-04-05</note_date>
       <orig_rec_date>2002-04-16</orig_rec_date>
       <recording_information></recording_information>
   </original_terms>
<address>address</address>

请告诉我该怎么做

在asp.net节点中添加xml节点

我认为你需要一个根元素。

XElement root = new XElement("root",
                    new XElement("state_tax_pin", state_tax_pin),
                    new XElement("original_terms",
                        new XElement("loan_amount", loan_amount),
                        new XElement("note_date", note_date.ToString("yyyy-MM-dd")),
                        new XElement("orig_rec_date", rig_rec_date.ToString("yyyy-MM-dd")),
                        new XElement("recording_information", recording_information)
                    ),
                    new XElement("address", address)
                );
Console.WriteLine(root.ToString());