使用c#连接XML数据
本文关键字:数据 XML 连接 使用 | 更新日期: 2023-09-27 17:54:20
我将使用c#在XML中连接表1和表2。谁能给我提供一个c#代码来实现上述场景?
表1
<REF_GANGGUAN_IRAMA>
<ID>1</ID>
<DESCRIP>Sinus</DESCRIP>
<DESCRIP_DTL>- 3 or more continuous beats satisfied with all of the following: 1. Duration QRS < 120 ms or duration QRS = 120 ms and
- 30 < axis QRS < 150 (QRS(V1) > 0 mV) or
- 60 < axis QRS < 120 (QRS(V1) = 0 mV) 2. P wave is normal 3. 120 = interval PR = 200 ms- 60 = HR < 100 bpm</DESCRIP_DTL>
</REF_GANGGUAN_IRAMA>
<REF_GANGGUAN_IRAMA>
<ID>2</ID>
<DESCRIP>SA Exit Block</DESCRIP>
</REF_GANGGUAN_IRAMA>
<REF_GANGGUAN_IRAMA>
<ID>3</ID>
<DESCRIP>Wandering Pacemaker</DESCRIP>
</REF_GANGGUAN_IRAMA>
表2:
<REF_JENIS_GANGGUAN_IRAMA>
<ID>1</ID>
<DESCRIP>Bradikardi</DESCRIP>
</REF_JENIS_GANGGUAN_IRAMA>
<REF_JENIS_GANGGUAN_IRAMA>
<ID>2</ID>
<DESCRIP>Takikardi</DESCRIP>
</REF_JENIS_GANGGUAN_IRAMA>
<REF_JENIS_GANGGUAN_IRAMA>
<ID>3</ID>
<DESCRIP>Disritmia</DESCRIP>
</REF_JENIS_GANGGUAN_IRAMA>
我需要读取上述两个xml文件,并将其写入一个新的xml文件与选定的元素?
输出: <REF_JENIS_GANGGUAN_IRAMA>
<ID>1</ID>
<DESCRIP>Bradikardi</DESCRIP>
<ID_GANGGUAN_IRAMA>1</ID_GANGGUAN_IRAMA>
<GANGGUAN_IRAMA>Sinus</GANGGUAN_IRAMA>
</REF_JENIS_GANGGUAN_IRAMA>
<REF_JENIS_GANGGUAN_IRAMA>
<ID>2</ID>
<DESCRIP>Takikardi</DESCRIP>
<ID_GANGGUAN_IRAMA>1</ID_GANGGUAN_IRAMA>
<GANGGUAN_IRAMA>Sinus</GANGGUAN_IRAMA>
</REF_JENIS_GANGGUAN_IRAMA>
<REF_JENIS_GANGGUAN_IRAMA>
<ID>3</ID>
<DESCRIP>Disritmia</DESCRIP>
<ID_GANGGUAN_IRAMA>1</ID_GANGGUAN_IRAMA>
<GANGGUAN_IRAMA>Sinus</GANGGUAN_IRAMA>
</REF_JENIS_GANGGUAN_IRAMA>
这是我的代码,请修改
代码:
ListItemPopup irm;
DataSet dsSet = new DataSet();
dsSet.ReadXml(Application.StartupPath + "''Referensi.data");
DataTable data = dsSet.Tables["REF_GANGGUAN_IRAMA"];
DataTable data1 = dsSet.Tables["REF_JENIS_GANGGUAN"];
for (int i = 0; i < data.Rows.Count; i++)
{
for(int j = 0; j < data1.Rows.Count; j++)
{
irm = new ListItemPopup(data1.Rows[i]["ID"], data1.Rows[i]["DESCRIP"], "");
cbjenis.Items.Add(irm);
}
}
这是您的问题的路径。
- 读取表1和表2的XML文件,看看它们是否有相同的记录 然后写入新的Xml文件。
伪代码:
string paht1=
string path2=
string path3=
load table1.xml
load table2.xml
for ()
{
get first value of table1
for()
{
get relevent value from table 2
write it in you new xml file
}
}
你最好试试这个……
编辑:根据你的编辑(你尝试过的解决方案),问题是什么??
用WriteXml把它写回来。
这个链接对你很有帮助- MSDN