问个关于xml很sb的问题

posaden 2006-11-11 11:43:35
看到别人blog上的xml
上面有个<rss version =2.0></rss>
这个是怎么弄出来的 答对有赏

-<rss version=2.0>//我想弄出这级目录


...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujia_0421 2006-11-11
  • 打赏
  • 举报
回复
对于你的Xml,你就先找到<rss>结点..

然后xmlElement.GetAttribute("version");
liujia_0421 2006-11-11
  • 打赏
  • 举报
回复
属于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);//显示子节点点文本
}
}
liujia_0421 2006-11-11
  • 打赏
  • 举报
回复
我不知道你什么情况,我是这么做的:
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
请按任意键继续. . .

posaden 2006-11-11
  • 打赏
  • 举报
回复
怎么回事?
posaden 2006-11-11
  • 打赏
  • 举报
回复
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出错
posaden 2006-11-11
  • 打赏
  • 举报
回复
恩 我看看先~

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧