using System.xml.linq;
XDocument doc=XDocument.Load("xml文档");
if(doc.Element("rtnCode").Value=="000"){}
手写板。。可能有错误
XDocument doc=XDocument.Load("xml文档");
if(doc.Element("rtnCode").Value=="000"){}
手写板。。可能有错误
解决方案 »
- asp.net C# 数据库添加信息有错误 代码提示有问题
- 请高手指点一下,有什么编程软件有128位的long double
- 发一面试题目。大伙都来顶。发表各自的看法。
- 如何在c#中实现将文本传到lpt1端口?
- C# 实现的FTP服务端和客户端无法连接
- C#中如何生成条码,并在水晶报表中显示出来
- 请教:C#中有关命名参数的调用方法
- .NET XML高级编程和ASP.NET/XML高级编程哪里有下载呀?
- 请问在.net怎样将两个事件关联起来,我点checkbox激发button click 事件?
- 用CSC.exe 如何编译带有App.config的源程序
- vs2005怎样完全删除添加过事件的控件
- C#中如何实现用户控件的键盘事件?
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplicationTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
String xml = @"<?xml version=""1.0"" encoding=""UTF-8"" ?>
<Package>
<totalCount>45</totalCount>
<MaxId>2878419</MaxId>
<Message>
<DeliverMessage>
<Id>2878419</Id>
<Userid>guodcy</Userid>
<Srctermid>07168305533</Srctermid>
<Desttermid>07168305533</Desttermid>
<Content>湖电信测试</Content>
<Receivetime>2010-06-27 21:26:54.0</Receivetime>
</DeliverMessage>
</Message>
</Package>";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);
//Console.WriteLine("totalCount : " + doc.GetElementsByTagName("totalCount")[0].FirstChild.Value);
textBox1.Text = "total:"+doc.GetElementsByTagName("totalCount")[0].FirstChild.Value+"\r\n";
foreach (System.Xml.XmlNode node in doc.GetElementsByTagName("DeliverMessage"))
{
textBox1.Text = textBox1.Text + "id:" + node["Id"].FirstChild.Value + "\r\n";
textBox1.Text = textBox1.Text + "Userid:" + node["Userid"].FirstChild.Value + "\r\n";
textBox1.Text = textBox1.Text + "Srctermid:" + node["Srctermid"].FirstChild.Value + "\r\n";
textBox1.Text = textBox1.Text + "Desttermid:" + node["Desttermid"].FirstChild.Value + "\r\n";
textBox1.Text = textBox1.Text + "Content:" + node["Content"].FirstChild.Value + "\r\n";
textBox1.Text = textBox1.Text + "Receivetime:" + node["Receivetime"].FirstChild.Value + "\r\n";
}
}
}
}
using System.Windows.Forms;
using System.Xml;namespace xmlNode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("1.xml");
XmlNode xn = xmldoc.SelectSingleNode("items/rtnCode");
string s = xn.InnerText;
}
}
}s就是 你要的值 你再根据这个值判断 执行啥子
doc.Load("");
XmlNode node=doc.SelectSingleNode("//rtnCode");
if(node!=null){}
可以参考
http://www.w3school.com.cn/xmldom/met_node_selectsinglenode.asp
xmldoc.Load("xml路径");
XmlNode node= xmldoc.SelectSingleNode("//rtnCode");
if(node!=null)
string s = node.InnerText;