使用C#读取xml文件 [英] Reading an xml file using C#

查看:109
本文介绍了使用C#读取xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想阅读以下具有相同元素名称和不同属性的xml文件我希望像[Depositor 1,prakash,Check]这样的值提前感谢



im want to read the below xml file having same element name and differet attributes i want the values like [Depositor 1,prakash,Cheque] thanks in advance

<subform name="sfDepositorDetails" presence="visible">
                  <instanceManager name="_sfDepositor" />
                  <subform name="sfDepositor">
                    <field name="lblKeyDepositor">
                      <value>
                        <text>Depositor 1</text>
                      </value>
                    </field>
                    <field name="txtDepositorName">
                      <value>
                        <text>prakash</text>
                      </value>
                    </field>
                    <field name="ddHSBCFunds">
                      <value override="1">
                        <text>Cheque</text>
                      </value>
                    </field>
                  </subform>

推荐答案

请参阅:

通过XMLDocument和XDocument解析XML文档 [ ^ ]



希望它有所帮助!
Please refer:
Parse XML Documents by XMLDocument and XDocument[^]

Hope it helps!


下面是一些链接,它可能对你有帮助



http://www.c -sharpcorner.com/UploadFile/167ad2/read-xml-file-using-xml-reader-in-C-Sharp/ [ ^ ]



http://csharp.net-informations.com/xml/ how-to-read-xml.htm [ ^ ]
Below are some links, It might helps you

http://www.c-sharpcorner.com/UploadFile/167ad2/read-xml-file-using-xml-reader-in-C-Sharp/[^]

http://csharp.net-informations.com/xml/how-to-read-xml.htm[^]


StringBuilder str = new StringBuilder();

XmlDocument Doc = new XmlDocument();

string str1 = File.ReadAllText(XMLFile1.xml);

Doc.Load(XMLFile1.xml);



foreach(Doc.SelectNodes中的XmlNode节点(// text))

{

str.Append(node.InnerText);

str.Append(,);

}
StringBuilder str = new StringBuilder();
XmlDocument Doc = new XmlDocument();
string str1 = File.ReadAllText("XMLFile1.xml");
Doc.Load("XMLFile1.xml");

foreach (XmlNode node in Doc.SelectNodes("//text"))
{
str.Append(node.InnerText);
str.Append(",");
}


这篇关于使用C#读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆