读取这样的XML。 现在要读xCode节点的值,要怎么读呢?<?xml version="1.0" encoding="gb2312"?>
<ActionResult>
<xMsgID>1265268631</xMsgID>
<xCode>1002</xCode>
<xMessage>不存在或已过期</xMessage>
<xSign>0671f0c1b2b377f2dce9f3f1e9cea72e</xSign>
<xValue>12</xValue>
</ActionResult>关键部分代码高手可以提供一下。谢谢。。
<ActionResult>
<xMsgID>1265268631</xMsgID>
<xCode>1002</xCode>
<xMessage>不存在或已过期</xMessage>
<xSign>0671f0c1b2b377f2dce9f3f1e9cea72e</xSign>
<xValue>12</xValue>
</ActionResult>关键部分代码高手可以提供一下。谢谢。。
解决方案 »
- 奇怪 输出窗口运行的时候为什么没了?
- 局域网拷贝文件的问题
- 串口通讯的迷惑
- 关于Session,Application,ViewState的区别!!1
- [winform问题]为什么用鼠标拖动滚动条表格就可以很好的显示,但是如果用鼠标的滚动轮的话,就会乱七八糟呢?
- 【【【【【【简单之极的正则表达式】】】】】】
- 紧急求救:des加密解密和数据库问题
- 关于DataGrid der中模板列的CheckBox的状态指
- c#中,有哪个方法包含了StretchBlt这个API,我希望图片在拉长时不会失真(dramImage)?
- 初学C#,请多帮忙,关于数据库事务控制
- 已添加项。字典中的关键字
- 如何改变textBox中指定文字的颜色?
XmlDocument doc = new XmlDocument();
doc.Load("test1.xml");
XmlNode node = doc.SelectSingleNode("//xCode");
if (node != null)
{
string str= node.InnerText;
}
XmlDocument xml = new XmlDocument();
xml.Load(@"F:\3.xml");
XmlNode xl = xml.SelectSingleNode("ActionResult/xCode");
if (xl != null)
{
Console.WriteLine(xl.InnerText);
}
用LINQ TO XML 最容易了.
{
string fn = XmlPath;//这里就是xml文件地址
if (File.Exists(fn))
{
XmlTextReader reader = null;
try
{
reader = new XmlTextReader(fn);
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
switch (reader.LocalName)
{
case "xCode":
string str = reader.ReadString(); //得到你要的东西了
break;
//这里加上case 语句,可以得到别的东西了
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("未知错误!\n" + ex.Message, "error", MessageBoxButtons.OK);
}
finally
{
reader.Close();
}
}
}
doc.Load("a.xml");
string str;
XmlNode node = doc.SelectSingleNode("ActionResult/xCode");
if (node != null)
{
str=node.InnerText;
}
哎 我都放弃xml了3.5之后用json还可以直接序列化成对象
doc.Load("test1.xml");
XmlNode node = doc.SelectSingleNode("./xCode");
if (node != null)
{
string str= node.InnerText;
}