xml简单问题高手 帮帮 忙在线 等(立刻揭帖 急~~~~~~~~~~~~~)

沈逸 2004-04-09 09:59:05
我有个 xml文件 里面的内容是
<?xml version="1.0" encoding="utf-8"?>
<News>
<New>
<Title>
fewfwefe
</Title>
<Content>
sefwefwef
</Content>
</New>
</News>

我想 用 代码 把 <?xml:stylesheet type="text/xsl" href="../../css/News.xslt"?> 这句话 写道 上面的 xml文件里面 该怎么写
用XmlTextWriter 行吗 还是 用 XmlDocument写
高手 帮帮 急 在线等 解决了 立刻揭帖
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wudixiaocaoren 2004-04-09
  • 打赏
  • 举报
回复
后台:using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
using System.Text;
namespace 有xml里添加内容
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
int count=0;

try
{
StreamReader reader=File.OpenText(Request.MapPath("myxml.xml"));
StreamWriter writer=new StreamWriter(Request.MapPath("sample.xml"));
while(reader.Peek()!=-1)
{
count++;
writer.WriteLine(reader.ReadLine());
if(count==1)
{
writer.WriteLine( TextBox1.Text.Trim());

}

}
reader.Close();
writer.Close();
}

catch(Exception err)
{
Response.Write(err.ToString());
}



}
}
}
wudixiaocaoren 2004-04-09
  • 打赏
  • 举报
回复
前台:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="有xml里添加内容.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute; TOP: 264px" runat="server"
Text="Button" Width="128px"></asp:Button>
<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 88px; POSITION: absolute; TOP: 200px" runat="server"
Width="448px" Height="32px"><?xml:stylesheet type="text/xsl" href="../../css/News.xslt"?> </asp:TextBox></FONT>
</form>
</body>
</HTML>
沈逸 2004-04-09
  • 打赏
  • 举报
回复
可是 我要 用xmldocument.load()
方法load这个xml文件阿
可使我 把<?xml-stylesheet?>先 写进去 后
load的时候 就抱错 说是 无法 解析<?xml-stysheet?>指令
能 不能先 load后
然后把 <?xml-stylesheet?>指令写进去呢
谢谢 立刻揭帖
wudixiaocaoren 2004-04-09
  • 打赏
  • 举报
回复
关键的地方在于: Writer.WriteProcessingInstruction("Read","Information");//写出在名称和文本之间带有空格的处理指令,可用来指出用什么文件来解析此XML

/* String PItext="type='text/xsl' href='book.xsl'";
writer.WriteProcessingInstruction("xml-stylesheet", PItext);

* */
wudixiaocaoren 2004-04-09
  • 打赏
  • 举报
回复
XmlTextWriter Writer=new XmlTextWriter("sample.xml",System.Text.Encoding.Default);//会以gb2312的格式写XML
Writer.Formatting=Formatting.Indented;//设置缩进


Writer.WriteStartDocument();
Writer.WriteComment("特别说明:这是使用ASP.NET的好处呀!");//写注译
Writer.WriteProcessingInstruction("Read","Information");//写出在名称和文本之间带有空格的处理指令,可用来指出用什么文件来解析此XML

/* String PItext="type='text/xsl' href='book.xsl'";
writer.WriteProcessingInstruction("xml-stylesheet", PItext);

* */



Writer.WriteStartElement("i","Info","urn:Info");

Writer.WriteStartElement("Name","");
Writer.WriteString("黄海呀!");
Writer.WriteEndElement();

Writer.WriteStartElement("Address","");
Writer.WriteString("深圳市南山区前海路北大附中南山分校");
Writer.WriteEndElement();

Writer.WriteEndDocument();

Writer.Close();
bitsbird 2004-04-09
  • 打赏
  • 举报
回复
<%@ Page Language="vb" validateRequest=false AutoEventWireup="false" Codebehind="WebForm9.aspx.vb" Inherits="WebApplication2.WebForm9"%>
<%@import namespace="system.xml"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
<xsl:value-of select="//title" /></TITLE>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<script runat="server">
sub huifu(sender as object,e as eventargs)
Dim filedom as New XmlDocument
filedom.load("g:\books.xml") '装载当前文件,为了添加节点
dim filedom2 as xmlnode = filedom.createElement("reply")
filedom2.innerXml = vbCrLf & " <anthor>123</anthor>" & vbCrLf & " <date>" & Now & "</date>" & vbCrLf & " <gengxindate>" & Now & "</gengxindate>" & vbCrLf & " <body>" & neirong.value & "</body>" & vbCrLf & " "
filedom.DocumentElement.appendChild(filedom2)
filedom.save("g:\books.xml")

End Sub
</script>

</HEAD>
<BODY topMargin="5">
<form id="myform" method="post" runat="server">
<textarea id="neirong" style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; BORDER-LEFT: black 1px solid; WIDTH: 100%; BORDER-BOTTOM: black 1px solid; HEIGHT: 180px"
name="neirong" runat="server"></textarea>
<asp:button id="tijiao" style="BORDER-RIGHT: #eeeeee 1px solid; BORDER-TOP: #eeeeee 1px solid; BORDER-LEFT: #eeeeee 1px solid; BORDER-BOTTOM: #eeeeee 1px solid; BACKGROUND-COLOR: #dddddd"
onclick="huifu" runat="server" text="提交回复"></asp:button></form>
</BODY>
</HTML>

62,074

社区成员

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

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

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

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