问个关于xml很sb的问题 看到别人blog上的xml 上面有个<rss version =2.0></rss>这个是怎么弄出来的 答对有赏-<rss version=2.0>//我想弄出这级目录 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 属于Attribute...举个例子:<?xml version="1.0" encoding="gb2312"?><bookstore> <book genre="fantasy" ISBN="2-3631-4"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.95</price> </book></bookstore>读取所有数据:XmlDocument xmlDoc=new XmlDocument();xmlDoc.Load("bookstore.xml");XmlNode xn=xmlDoc.SelectSingleNode("bookstore"); XmlNodeList xnl=xn.ChildNodes; foreach(XmlNode xnf in xnl) { XmlElement xe=(XmlElement)xnf; Console.WriteLine(xe.GetAttribute("genre"));//显示属性值 Console.WriteLine(xe.GetAttribute("ISBN")); XmlNodeList xnf1=xe.ChildNodes; foreach(XmlNode xn2 in xnf1) { Console.WriteLine(xn2.InnerText);//显示子节点点文本 } } 对于你的Xml,你就先找到<rss>结点..然后xmlElement.GetAttribute("version"); private void xml() { XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load(Server.MapPath("../xml/bookstore.xml")); XmlNode xn=xmlDoc.SelectSingleNode("bookstore"); XmlNodeList xnl=xn.ChildNodes; foreach(XmlNode xnf in xnl) { XmlElement xe=(XmlElement)xnf; Console.WriteLine(xe.GetAttribute("genre"));//显示属性值 XmlNodeList xnf1=xe.ChildNodes; foreach(XmlNode xn2 in xnf1) { Console.WriteLine(xn2.InnerText);//显示子节点点文本 } } XmlTextWriter xw = new XmlTextWriter(Server.MapPath("rss3.xml"), Encoding.UTF8); }出错了 文件第一行 40出错 我不知道你什么情况,我是这么做的:using System;using System.Collections.Generic;using System.Text;using System.Threading;using System.IO;using System.Web;using System.Xml;namespace TestConsole{ class Program { static void Main(string[] args) { xml(); } public static void xml() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../bookstore.xml"); XmlNode xn = xmlDoc.SelectSingleNode("bookstore"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xnf in xnl) { XmlElement xe = (XmlElement)xnf; Console.WriteLine(xe.GetAttribute("genre"));//显示属性值 XmlNodeList xnf1 = xe.ChildNodes; foreach (XmlNode xn2 in xnf1) { Console.WriteLine(xn2.InnerText);//显示子节点点文本 } } } }}bookstore.xml文件与"Program.cs"在同一目录下...输出如下:fantasyOberon's LegacyCorets, Eva5.95请按任意键继续. . . 请问下用过itextsharp可以实现在已有pdf插入图片吗? ERROR 1001 软件打包后直接运行的问题 在同一个form里,oledbDataAdapter的实例怎样可以重复使用? 验证码验证的时候,Session总是为空 关于引用类型的参数传递??? datagrid的自动套用格式问题!谢了 请问如何实现C#自动点击网页中的其中一个按钮 请问这段代码的x,y怎么定义? ##序列化问题##用SoapFormatter序列化保存后,再读取,为何提示错误,具体内容如下 =========200分求一有关Rtf和正则表达式的问题? jmail附件乱码问题
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>读取所有数据:
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
XmlNodeList xnl=xn.ChildNodes;
foreach(XmlNode xnf in xnl)
{
XmlElement xe=(XmlElement)xnf;
Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
Console.WriteLine(xe.GetAttribute("ISBN"));
XmlNodeList xnf1=xe.ChildNodes;
foreach(XmlNode xn2 in xnf1)
{
Console.WriteLine(xn2.InnerText);//显示子节点点文本
}
}
{
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load(Server.MapPath("../xml/bookstore.xml"));
XmlNode xn=xmlDoc.SelectSingleNode("bookstore");
XmlNodeList xnl=xn.ChildNodes;
foreach(XmlNode xnf in xnl)
{
XmlElement xe=(XmlElement)xnf;
Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
XmlNodeList xnf1=xe.ChildNodes;
foreach(XmlNode xn2 in xnf1)
{
Console.WriteLine(xn2.InnerText);//显示子节点点文本
}
}
XmlTextWriter xw = new XmlTextWriter(Server.MapPath("rss3.xml"), Encoding.UTF8); }
出错了 文件第一行 40出错
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO;
using System.Web;
using System.Xml;namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
xml();
}
public static void xml()
{
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("../../bookstore.xml"); XmlNode xn = xmlDoc.SelectSingleNode("bookstore"); XmlNodeList xnl = xn.ChildNodes; foreach (XmlNode xnf in xnl)
{
XmlElement xe = (XmlElement)xnf;
Console.WriteLine(xe.GetAttribute("genre"));//显示属性值
XmlNodeList xnf1 = xe.ChildNodes;
foreach (XmlNode xn2 in xnf1)
{
Console.WriteLine(xn2.InnerText);//显示子节点点文本
}
}
} }
}
bookstore.xml文件与"Program.cs"在同一目录下...
输出如下:fantasy
Oberon's Legacy
Corets, Eva
5.95
请按任意键继续. . .