<%@
Import
Namespace="System.Data"
%>
<%@
Import
Namespace="System.Data.SqlClient"
%>
<html>
<head>
<script
language="C#"
runat="server">
public
DataView
Source
public
DataSet
ds
public
bool
getSchema,
getData
public
void
Submit_Click(Object
sender,
EventArgs
evt)
{
if
(IsPostBack)
{
SqlConnection
myConnection
=
new
SqlConnection(ConnectString.Value)
SqlDataAdapter
myCommand
=
new
SqlDataAdapter(myText.Value,
myConnection)
ds
=
new
DataSet()
myCommand.Fill(ds,
"表")
Source
=
new
DataView(ds.Tables[0])
getSchema
=
GetSchema.Checked
getData
=
GetData.Checked
MyDataGrid.DataSource=Source
MyDataGrid.DataBind()
}
}
</script>
</head>
<body
bgcolor="ffffcc">
<h3><font
face="宋体">SQL
到
XML
生成器</font></h3>
<form
runat="server">
<table
border=0
cellpadding=5
style="font:10.5pt
宋体">
<tr>
<td
colspan="2">
<b>连接字符串:</b><br>
<input
id="ConnectString"
type="text"
value="server=(local)database=pubsuid=sapwd=1234"
size="85"
runat="server">
</td>
</tr>
<tr>
<td
colspan="2">
<b>查询:</b>迹渗<br>
<input
id="myText"
type="text"
value="SELECT
*
FROM
Authors"
size="85"
runat="server">
</td>
</tr>
<tr>
<td>
<input
type="radio"
id="GetSchema"
name="Mode"
runat="server"/>获取
XML
架构<br>
<input
type="radio"
id="GetData"
name="Mode"
runat="server"/>获取
XML
数据<br>
<input
type="radio"
id="GetBoth"
name="Mode"
checked
runat="server"/>两者都获取
</td>
<td
valign="top">
<input
type="submit"
runat="server"
OnServerClick="Submit_Click">
</td>
</tr>
<tr>
<td
colspan="2">
<%
if
(Page.IsPostBack)
{
%>
<b>结果:</b><逗州巧br>
<textarea
cols=80
rows=25>
<%
if
(getSchema)
ds.WriteXmlSchema(Response.Output)
else
if
(getData)
ds.WriteXml(Response.Output,
XmlWriteMode.IgnoreSchema)
else
ds.WriteXml(Response.Output,
XmlWriteMode.WriteSchema)
%>
</textarea>
<%
}
%>
</td>
</tr>
<tr>
<td
colspan="2">
<%
if
(Page.IsPostBack)
{
%>
<b>数山键据:</b><br>
<%
}
%>
<ASP:DataGrid
id="MyDataGrid"
BackColor="#EDBE7B"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="宋体"
Font-Size="8pt"
HeaderStyle-BackColor="#DC6035"
EnableViewState="false"
runat="server"
/>
</td>
<tr>
</table>
</form>
</body>
</html>
用C#来做。要用XmlTextWriter向TXT文件中写内容。
using
System.Xml
using
System.Text
XmlTextReader
xmlReader
=
null
xmlReader
=
new
XmlTextReader(mDocument)
//mDocument参数为xml文档名字
while(xmlReader.Read())
{
if(xmlReader.NodeType
==
XmlNodeType.Element)
{
while(xmlReader.MoveToNextAttribute())
{
//用XmlTextWriter类将xmlReader.Name和xmlReader.Value写入HTML做
//相应的处理
}
if(xmlReader.IsEmptyElement)
{
}
else
{
}
}
else
if(xmlReader.NodeType
==
XmlNodeType.EndElement)
{
//做自己的处理
}
else
if(xmlReader.NodeType
==
XmlNodeType.Text)
{
if
(xmlReader.Value.Length
!=
0)
{
//将xmlReader.Value
写入TXT中的处理
}
}
}
//end
of
~while(xmlReader.Read())
展开
1 读入文件内容,将xxx,xxx,xxx的格式保存到某个字符串变量,2 用Stringstoken将这些变量转换成数组保存.
3 XML的文件读写一般都用dom4j来实现,用dom4j将数组中的内容按照你所需要的格式生成xml文件,给那个方键岁族雀裂法调用即可.
import org.dom4j.Attribute
import org.dom4j.DocumentException
import org.dom4j.DocumentHelper
import org.dom4j.Element
...............
//创建一个Xml文件
Element user=DocumentHelper.createElement("User")
user.addAttribute("type", "user")
user.addElement("name").addAttribute("type", "PinYin"稿弊).setText("Julysea")
user.addElement("age").setText("29")
String oneXml=user.asXML()
BufferedWriter out=new BufferedWriter(new FileWriter("oneXml.xml"))
out.write(oneXml)
out.close()
XML还有HTML还有TXT本身就是文本文件格式的如果你想让备滚举你的XML文件里的文本符合XML语言规备宽范仿碧,可以类似这样写: <?xml version="1.0" encoding="utf-8"?><bcaster>
<item item_url="Banners/01.jpg" link="" />
<item item_url="Banners/02.jpg" link="" />
<item item_url="Banners/03.jpg" link="" />
</bcaster>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)