本文介绍了如何获得子节点&使用C#动态生成父节点的子节点的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友们,
我正在尝试使用c#动态创建xml文件.我想创建xml文件,如下所示:
Hi friends,
i m trying to creat a xml file dynamically using c#.i want to create xml file like this :
<?xml version="1.0" encoding="utf-8" ?>
- <Hospitalizations>
- <Hospitalization Id="">
<Patient_Id>REG-10010</Patient_Id>
<FileId>REG-10010</FileId>
<date_of_admission>29/07/2010 13:56:16</date_of_admission>
<date_of_discharge>31/07/2010 14:55:49</date_of_discharge>
<ward Date="08/12/2011">General</ward>
<admission_type>Genral</admission_type>
- <Wards>
<ward Date="08/12/2011">General</ward>
<ward Date="08/12/2011">General2</ward>
</Wards>
<primary_department>Obs. & Gynae</primary_department>
<primary_doctor_name>Vandana Bansal MS,FCGP,D.Phil</primary_doctor_name>
<discharge_type />
<discharge_details>31/07/2010 14:55:49,</discharge_details>
- <diagnosis>
<entry>None</entry>
</diagnosis>
</Hospitalization>
</Hospitalizations>
亲切地建议我如何检索子节点&动态添加到主XML节点.
谢谢&问候
Gulam Hussain
kindly suggest me that how to retrieve child node & Add Into Main XML Node dynamically.
Thanks & Regards
Gulam Hussain
推荐答案
Hospitalizations.Descendants.Element("Hospitalization1").Add(new XElement("List of Procedures"));
如Addy Tas所建议,XPath(System.Linq.XPath)可能在此处可用于访问元素:[ ^ ].
As suggested by Addy Tas, XPath (System.Linq.XPath) may be useful here for accessing elements:[^].
这篇关于如何获得子节点&使用C#动态生成父节点的子节点的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!