-- 作者:missing62
-- 发布时间:5/9/2008 11:30:00 PM
-- 一个不支持汉字的XML例子,请大虾帮忙
本人用VB.net做的XML添加数据文件,为什么会自动把 encoding="utf-8"清楚掉 导致添加的XML数据不支持汉字,请大虾帮忙指导 文件名字add.aspx <%@ Page Language="VB" AutoEventWireup="false" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System.Data" %> <script runat="server"> Protected Sub AddClick(ByVal sender As Object, ByVal e As System.EventArgs) Try Dim dataFile As String = "gbook.xml" 'the next line wraps Dim fin As New FileStream(Server.MapPath(dataFile), FileMode.Open, FileAccess.Read, FileShare.ReadWrite) 'this line also wraps Dim fout As New FileStream(Server.MapPath(dataFile), FileMode.Open, FileAccess.Write, FileShare.ReadWrite) Dim guestData As New DataSet() Dim newRow As DataRow err.Text = "" guestData.ReadXml(fin) fin.Close() newRow = guestData.Tables(0).NewRow() newRow("Name") = Name.Text newRow("Chrono") = DateTime.Now.ToString() newRow("Email") = Email.Text newRow("Comments") = Comments.Text guestData.Tables(0).Rows.Add(newRow) guestData.WriteXml(fout, XmlWriteMode.WriteSchema) fout.Close() pnlAdd.Visible = False pnlThank.Visible = True Catch edd As Exception err.Text = "Error Writing file at:" & edd.ToString() End Try End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Add Entry</title> </head> <body> <br /> <br /> <h3 align="center">Guestbook post Page.</h3> <br /> <asp:Label ID="err" Text="" style="color:#ff0000" runat="server" /> <asp:Panel ID="pnlAdd" runat="server"> <form action="add.aspx" runat="server"> <table border="0" width="80%" align="center"> <tr> <td><b>Sign-in My GuestBook</b></td> <td> </td> </tr> <tr> <td>Name:</td> <td><asp:TextBox Text="" ID="Name" runat="server" /> <asp:RequiredFieldValidator ID="buttom1" ControlToValidate="Name" Display="static" runat="server">*</asp:RequiredFieldValidator> </td> </tr> <tr> <td>E_mail:</td> <td><asp:TextBox Text="" ID="Email" runat="server" /> <asp:RequiredFieldValidator ID="buttom3" ControlToValidate="Email" Display="static" runat="server">*</asp:RequiredFieldValidator> <asp:RequiredFieldValidator ID="buttom4" runat="server" ControlToValidate="Email" ValidationExpression="[\W-]+@([\w-]+\.)+[\w-]+" Display="static" Font-Names="verdana" Font-Size="10pt">please enter a valid email address</asp:RequiredFieldValidator> </td> </tr> <tr> <td>Comments:</td> <td><asp:TextBox TextMode="multiline" ID="Comments" Columns="25" Rows="4" runat="server" /> </td> </tr> <tr> <td colspan="2"> <asp:Button ID="buttom2" Text="Submit Post" OnClick="AddClick" runat="server" /> </td> </tr> </table> </form> </asp:Panel> <asp:Panel ID="pnlThank" Visible="false" runat="server"> <p align="center"><b>Thank you for posting in my Guestbook!</b><br /> <a href="viewplain.aspx">Click here</a>to view GuestBook. </p> </asp:Panel> </body> </html> 文件名字:gbook.xml <xs:schema id="gbook" targetNamespace="gb2312" xmlns:mstns="gb2312" xmlns="gb2312" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="gbook" msdata:IsDataSet="true" msdata:Locale="en-US"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="gbooky" form="unqualified"> <xs:complexType> <xs:sequence> <xs:element name="Name" form="unqualified" type="xs:string" minOccurs="0" /> <xs:element name="Chrono" form="unqualified" type="xs:string" minOccurs="0" /> <xs:element name="Email" form="unqualified" type="xs:string" minOccurs="0" /> <xs:element name="Comments" form="unqualified" type="xs:string" minOccurs="0" /> <xs:element name="DateTime" form="unqualified" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> </gbook> 文件名字:viewplan.aspx <%@ Page Language="VB" AutoEventWireup="false" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>XML Control Test</title> </head> <body bgcolor="#fffffa"> <!-- line 7 warps --> <asp:Xml ID="gbook" DocumentSource="gbook.xml" TransformSource="gbook.xsl" runat="server" /> </body> </html> 文件名字:gbook.xsl <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:for-each select="gbooky"> <table with="400"> <!--this line wraps --> <tr> <font color="#ffffff" face="Arial Black"> <xsl:value-of select="Name"/> </font> </tr> <!--this line wraps --> <tr> <font color="#ffffff" face="Arial Black"> <br/> <xsl:value-of select="Email"/> </font> </tr> <tr> <font face="Arial Black"> <br/> <p> <xsl:value-of select="userid"/> </p> <p></p> </font> </tr> <tr> <font face="Arial Black"> <br/> <p> <xsl:value-of select="DateTime"/> </p> <p></p> </font> </tr> </table> </xsl:for-each> </xsl:template> </xsl:stylesheet>
|