帮忙看下这几行创建xml的代码有什么错误

guhonglangzi002 2010-09-08 10:23:01
帮忙看下这几行创建xml的代码有什么错误,应该怎样改?

代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;


namespace xml_test2
{
class Program
{
public static void CreateDocument( )
{
XDocument xdoc = new XDocument( new XDeclaration("1.0","utf-8","yes") , new XElement("Root","root") );
xdoc.Save(path);

}

static void Main(string[] args)
{
}
}
}
...全文
85 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
萨拉嘿 2010-09-09
  • 打赏
  • 举报
回复
path应该是在启动项目的debug文件夹下 你可以使用相对路径设置 例如path="../../Test.xml"
guhonglangzi002 2010-09-08
  • 打赏
  • 举报
回复
恩,path没有定义,如果要进行定义,在项目的根目录下是不是这样定义。path="../"。

能把在下的这段代码,改成正确的代码吗?运行没有结果啊,不知道什么原因。
十八道胡同 2010-09-08
  • 打赏
  • 举报
回复
创建xml的代码 网上真的很多
十八道胡同 2010-09-08
  • 打赏
  • 举报
回复
你的path没定义
wuyq11 2010-09-08
  • 打赏
  • 举报
回复
XDocument d = new XDocument(new XDeclaration("1.0", "utf-8", "true"),
new XComment(""),
new XProcessingInstruction("xml-stylesheet", "href='mystyle.css' title='Compact' type='text/css'"),
new XElement("Book",
new XElement("Title", ""),
));
XmlDocument xmldoc = new XmlDocument( ) ;
XmlNode xmlnode =xmldoc.CreateXmlDeclaration("1.0","gb2312",null);
xmldoc.AppendChild ( xmlnode ) ;

111,129

社区成员

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

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

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