一个XML的字符串怎么去解析 <?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://tempuri.org/">-5</string> 我要取-5出来 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //这样的可以吧(C#的)://上面的加载省略哈……XmlNode node = xmlDoc.SelectSingleNode("string");string nodeText = node.InnerText;//nodeText就是获取的值 应该有好几种方法的,下面我说2种 1种是3楼说的通过DataSet 读取xml 然后在DataSet里取 DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("xmlFile.xml")); 以下就不说了 2种是通过XmlDocument XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(this.m_xmlFilePath); System.Xml.XmlNodeList xmlNL = xmlDoc.SelectNodes("string"); .... 不对呀那里来的xmlFile.xml我现在只有一个字符串内容是:<?xml version="1.0" encoding="utf-8" ?> <string xmlns="http://tempuri.org/">-5 </string> 我要取-5出来 XmlDocument xmlDoc = new XmlDocument(); smlDoc.LoadXml(/*字符串*/); 打错了 是XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(/*字符串*/); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(/*字符串*/);XmlNode xn0 = xmlDoc.SelectSingleNode("string")string result = xn0.InnerText;result为 -5 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(s); XmlNode node = xmlDoc.SelectSingleNode("http://tempuri.org/");出现异常怎么回事 http://tempuri.org/'”具有无效的标记 XmlNode node = xmlDoc.SelectSingleNode("http://tempuri.org/"); NODE("*****"); ***代表的是你的结点名称,“http://tempuri.org/”不是你的结点,怎么能够填写进去呢? http://tempuri.org/ 这个是属性值 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(s); XmlNode node = xmlDoc.SelectSingleNode("string");//这样都不对你们验证过我这样得到一个NULL string nodeText = node.InnerText;这样都不对你们验证过我这样得到一个NULL 完全搞定了 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath("XMLFile.xml")); String ss = xmlDoc.GetElementsByTagName("string")[0].Attributes[0].Value.ToString(); 这个取值,上面的取属性值 String sss = xmlDoc.GetElementsByTagName("string")[0].InnerText.ToString(); XmlNode node = xmlDoc.SelectSingleNode("string");string nodeText = node.InnerText; C sharp怎么调用DLL? 如何用winform实现登录网站? C# 怎么获取 EXecl 表格中有多少个工作薄 C#千古奇案之水晶报表问题求解 怎样把DataGrid中的数据修改保存到数据库中呢?? 做一个add-in,编译时候出现这三个警告,怎么办啊? 请教高手!!!C#打开文件问题 如何屏蔽alt+ctrl+del或是ALT+F4? GridView超链接问题 请问谁有C# Primer 中文版的程序代码 怎样在我的网页中增加可以让用户浏览网页时,下载我的控件的功能 字典表与常量的矛盾
//这样的可以吧(C#的):
//上面的加载省略哈……
XmlNode node = xmlDoc.SelectSingleNode("string");
string nodeText = node.InnerText;
//nodeText就是获取的值
应该有好几种方法的,下面我说2种
1种是3楼说的通过DataSet 读取xml 然后在DataSet里取 DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("xmlFile.xml"));
以下就不说了
2种是通过XmlDocument
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(this.m_xmlFilePath);
System.Xml.XmlNodeList xmlNL = xmlDoc.SelectNodes("string");
....
我现在只有一个字符串内容是:
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/">-5 </string>
我要取-5出来
smlDoc.LoadXml(/*字符串*/);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(/*字符串*/);
xmlDoc.LoadXml(/*字符串*/);
XmlNode xn0 = xmlDoc.SelectSingleNode("string")
string result = xn0.InnerText;
result为 -5
xmlDoc.LoadXml(s);
XmlNode node = xmlDoc.SelectSingleNode("http://tempuri.org/");
出现异常怎么回事
NODE("*****"); ***代表的是你的结点名称,“http://tempuri.org/”不是你的结点,怎么能够填写进去呢?
xmlDoc.LoadXml(s);
XmlNode node = xmlDoc.SelectSingleNode("string");
//这样都不对你们验证过我这样得到一个NULL
string nodeText = node.InnerText;
这样都不对你们验证过我这样得到一个NULL
完全搞定了 XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("XMLFile.xml"));
String ss = xmlDoc.GetElementsByTagName("string")[0].Attributes[0].Value.ToString();
这个取值,上面的取属性值
String sss = xmlDoc.GetElementsByTagName("string")[0].InnerText.ToString();
string nodeText = node.InnerText;