一个很简单问题~!!!!

FrostG 2003-09-30 09:43:49
在ASP.NET当中.我怎么把用户输入的信息写进XML文件里呢~!?我知道有这样一个类.
请问是哪个类...怎么用...谢谢了~!!!
...全文
47 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qimini 2003-09-30
  • 打赏
  • 举报
回复
昏,點'管理'
FrostG 2003-09-30
  • 打赏
  • 举报
回复
喔...这样啊...谢谢咯~!!!
对了...怎么给分数啊~!?
zhenwang 2003-09-30
  • 打赏
  • 举报
回复
给你一个简洁的步骤:
1、创建一个XMLDocument对象,用于载入存储信息的XML文件;
XmlDocument xdoc=new XmlDocument();
xdoc.Load(Server.MapPath("XML文件名.xml"));

2、创建一个新的主节点,并将它添加到跟节点下:
XmlElement parentnode=xdoc.CreateElement("MainNode");
xdoc.DocumentElement.PrependChild(parentnode);

3、创建所有用于存储信息的子节点:
XmlElement node1=xdoc.CreateElement("node1");
XmlElement node2=xdoc.CreateElement("node2");
......................

4、将上面创建的各个存储信息的节点添加到主节点下但并不包含最终的值:
parentnode.AppendChild(node1);
parentnode.AppendChild(node2);
...........................

5、将要添加的文本信息添加到各个节点中去:
node1.AppendChild("----文本信息---");
node2.AppendChild("----文本信息---");

6、保存存储信息的XML文件
xdoc.Save(Server.MapPath("xml文件名.xml"));

按照上面的方法创建的 xml文件将具有如下格式:
<?xml version="1.0" encoding="gb2312"?>
<mainnode>
<node1>....</node1>
<node2>.....</node2>
</mainnode>
qimini 2003-09-30
  • 打赏
  • 举报
回复
====================A sample From MSDN 2003

Input

data1|data2|data3|data4|data5

and you would like to transform it to :

Output

<data>
<item> data1 </item>
<item> data2 </item>
<item> data3 </item>
<item> data4 </item>
<item> data5 </item>
</data>

A method is created to tokenize the data in the file into individual data tokens. Each call to this function returns one of the data elements. The method takes in a StreamReader.


[C#]
public static String NextToken(StreamReader stream)
{
int temp = stream.Read();
String t1 = "";
while(temp != -1 && temp != (int)'|')
{
t1 += (char)temp;
temp = stream.Read();
}
return t1;
}

The code iterates through until there are no data tokens remaining; inserting each token into an XML document. This is done in the Main function, which takes two command line arguments. The first argument is the file to read from, the second is the file to write to. The comments within the code provide a description of the actions taking place.

[C#]
using System;
using System.IO;
using System.Xml;

namespace TextFiletoXml
{

class TextFiletoXml
{
public static String file;
public static StreamReader stream;
public static XmlTextWriter xwriter;
public static String val;
public static String NextToken(StreamReader stream)
{
int temp = stream.Read();
String t1 = "";
while(temp != -1 && temp != (int)'|')
{
t1 += (char)temp;
temp = stream.Read();
}

return t1;

}

public static void Main(string[] args)
{
file = args[0];

//Create a new stream representing the file we are
//reading from.
stream = new StreamReader(file, true);

//Create a new XmlTextWriter.
xwriter = new XmlTextWriter(args[1],System.Text.Encoding.UTF8);
//Write the beginning of the document including the
//document declaration. Standalone is true.

xwriter.WriteStartDocument(true);

//Write the beginning of the "data" element. This is
//the opening tag to our data

xwriter.WriteStartElement("data","www.alpineskihouse.com");

// Get the first data element from the file.
val = NextToken(stream);

//create a new element with each data token from //the stream.
while(val != "")
{

xwriter.WriteElementString("item","www.alpineskihouse.com", val);
val = NextToken(stream);
}
//End the "data" element.
xwriter.WriteEndElement();

//End the document
xwriter.WriteEndDocument();

//Flush the xml document to the underlying stream and
//close the underlying stream. The data will not be
//written out to the stream until either the Flush()
//method is called or the Close() method is called.
xwriter.Close();
}
}
}
qimini 2003-09-30
  • 打赏
  • 举报
回复
==================== From MSDN 2003

Input

data1|data2|data3|data4|data5

and you would like to transform it to :

Output

<data>
<item> data1 </item>
<item> data2 </item>
<item> data3 </item>
<item> data4 </item>
<item> data5 </item>
</data>

A method is created to tokenize the data in the file into individual data tokens. Each call to this function returns one of the data elements. The method takes in a StreamReader.


[C#]
public static String NextToken(StreamReader stream)
{
int temp = stream.Read();
String t1 = "";
while(temp != -1 && temp != (int)'|')
{
t1 += (char)temp;
temp = stream.Read();
}
return t1;
}

The code iterates through until there are no data tokens remaining; inserting each token into an XML document. This is done in the Main function, which takes two command line arguments. The first argument is the file to read from, the second is the file to write to. The comments within the code provide a description of the actions taking place.

[C#]
using System;
using System.IO;
using System.Xml;

namespace TextFiletoXml
{

class TextFiletoXml
{
public static String file;
public static StreamReader stream;
public static XmlTextWriter xwriter;
public static String val;
public static String NextToken(StreamReader stream)
{
int temp = stream.Read();
String t1 = "";
while(temp != -1 && temp != (int)'|')
{
t1 += (char)temp;
temp = stream.Read();
}

return t1;

}

public static void Main(string[] args)
{
file = args[0];

//Create a new stream representing the file we are
//reading from.
stream = new StreamReader(file, true);

//Create a new XmlTextWriter.
xwriter = new XmlTextWriter(args[1],System.Text.Encoding.UTF8);
//Write the beginning of the document including the
//document declaration. Standalone is true.

xwriter.WriteStartDocument(true);

//Write the beginning of the "data" element. This is
//the opening tag to our data

xwriter.WriteStartElement("data","www.alpineskihouse.com");

// Get the first data element from the file.
val = NextToken(stream);

//create a new element with each data token from //the stream.
while(val != "")
{

xwriter.WriteElementString("item","www.alpineskihouse.com", val);
val = NextToken(stream);
}
//End the "data" element.
xwriter.WriteEndElement();

//End the document
xwriter.WriteEndDocument();

//Flush the xml document to the underlying stream and
//close the underlying stream. The data will not be
//written out to the stream until either the Flush()
//method is called or the Close() method is called.
xwriter.Close();
}
}
}
qimini 2003-09-30
  • 打赏
  • 举报
回复
XmlWriter
========== 1.易支持库机制 ========== !!!易支持库的库信息、命令信息等等均使用某个结构储存!!!易源码中的自定义数据类型、类模块、组件即为支持库中的库定义数据类型!!!易语言 通过 GetNewInf() 获取支持库信息!!!所以支持库必须导出这个函数 ========== 2.支持库命令调用 ========== !!!支持库的命令调用方式也比较特殊!!!每个命令需要三个参数:返回值指针,参数数目,参数信息指针!!!做个一个库定义数据类型的方法,每个方法的第一个参数为指向该对象的结构指针 ========== 3.简单说下易源码 ========== !!!易保存源码时没有保存各信息名称(比如命令名、数据类型名),而是保存了索引!!!所以支持库内的各信息有必要时可以修改!!!但不要改动TA们的顺序,这会导致前期版本的源码出现问题 ========== 4.模版说明 ========== !!!本模版整天来说思路清晰,代码连小白都能理解!!!模版多数的参数使用通用型,使得模版简便!!!模版内没有多说废话, 直接把关键的过了一遍, 足够写支持库了!!!每条命令都演示了支持库的各种操作,能想到的都先写了!!!暂时没写组件,目前没什么时间了,玩着电脑也冷~!!!尽量抽时间将组件的开发也模块化!!!或者各位有心人士可参考 e\sdk\cpp\samples\HtmlView 写一下 ========== 5.关于静态库 ========== !!!本人目前只做了动态库,不做静态库原因很多!!!本来打算做静态库的,不过考虑到某些原因:!!!静态库误报,动态库转到静态库时也会出现一些未知问题!!!个人也建议使用独立编译,5.3已经恢复!!!更建议用 黑月Cool编译!!!或者直接就是一个“懒”字!!!!各路有心人士可动手改一下!!!我也弄好了静态连接名的录入机制 ========== 6.为何选择支持库 ========== !!!其实用模块扩展程序也是足够了!!!选择做支持库还是安全的!!!而且支持库有许多模块做不到的功能 ========== 7.关于易功能函数 ========== !!!顾名思义, 就是易内部提供给支持库的函数!!!主要的用法呢还是得参考 lib2.h(位于 e\sdk\cpp\elib\lib.h)!!!虽说是一个C++头文件,但是语文好点、懂易语言就能理解!!!小学生的语文水平就差不多啦!!!我还是把一些常用的写到了 类_易功能 这个类里面!!!各位同学可以看看、 、 ========== 【最后】 ========== !!!直说:本人纯属菜鸟一枚, 各路大神勿喷即可 ==========??【信息】??========== !!!模版:易支持库模版!!!作者:SalHe(Rabbit Group)!!!声明:大鸟勿喷即可!!!日期:2014年11月8日怎么编译我还是简单说一下,针对一下小白。编译的时候将文件名的后缀改为fne在放入易语言的支持库目录就好了支持库一发布后就不要修改数字签名和支持库文件名了

62,263

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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