新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → [求助]   有没有高手可以帮我解决一下 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 11189 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]   有没有高手可以帮我解决一下 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     020604111 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:4
      积分:72
      门派:XML.ORG.CN
      注册:2006/5/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给020604111发送一个短消息 把020604111加入好友 查看020604111的个人资料 搜索020604111在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看020604111的博客楼主
    发贴心情 [求助]   有没有高手可以帮我解决一下

    求助  :我的毕业设计是做一个基于XML机票信息发布系统,下面分别是机票的XML文件,XSL文件,以及将数据添加到XML文件中的WebForm1.aspx.cs,前两个文件都能正常运行并显示结果,但是在运行WebForm1.aspx.cs时就会出现如下的问题

    (所有的文件是放在faight文件夹中的)

    “/faight”应用程序中的服务器错误。
    --------------------------------------------------------------------------------

    意外的 XML 声明。 行 2,位置 3。
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

    异常详细信息: System.Xml.XmlException: 意外的 XML 声明。 行 2,位置 3。

    源错误:


    行 41:    {
    行 42:     XmlDocument xmlDoc = new XmlDocument();
    行 43:     xmlDoc.Load(Server.MapPath("tickets.xml"));
    行 44:     myXml.Document = xmlDoc;
    行 45:    }

    源文件: c:\inetpub\wwwroot\faight\webform1.aspx.cs    行: 43

    源代码如下:

    tickets.xml


    <?xml version="1.0" encoding="GB2312" standalone="yes"?>
    <?xml-stylesheet type="text/xsl" href="pp.xsl"?>
           <Air-Tickets  Date="2006/3/22">
         <Ticket>
         <From>西安</From>
         <To>东京</To>
         <DepartingTime>14:00</DepartingTime>
         <ArrivingTime>16:00</ArrivingTime>
         <price type="Economy"> 1180 </price>
         <price1 type="Business"> 1480 </price1>
         </Ticket>
         <Ticket>
            <From>西安</From>
         <To>首尔</To>
         <DepartingTime>16:00</DepartingTime>
         <ArrivingTime>18:00</ArrivingTime>
         <price type="Economy"> 1180 </price>
            <price1 type="Business"> 1480 </price1>
      </Ticket>
         <Ticket>
          <From> 西安</From>   
          <To>   纽约</To>
                <DepartingTime>09:00</DepartingTime>
          <ArrivingTime>11:00</ArrivingTime>
          <price type="‘Economy’"> 1080 </price >
             <price1 type="‘Business’"> 1380 </price1>
         </Ticket>
         <Ticket>
          <From> 西安</From >   
          <To>   新德里</To>
          <DepartingTime>13:00</DepartingTime>
          <ArrivingTime>15:00</ArrivingTime>
          <price type="‘Economy’"> 1080 </price >
          <price1 type="‘Business’"> 1380 </price1 >
       </Ticket>
       <Ticket>
          <From> 西安</From >   
          <To>   莫斯科</To>  
          <DepartingTime>17:00</DepartingTime>
           <ArrivingTime>19:00</ArrivingTime>
          <price  type="‘Economy’"> 1080 </price >
          <price1 type="‘Business’"> 1380 </price1 >
             </Ticket>
          </Air-Tickets>


    pp.xsl

      <?xml version="1.0" encoding="GB2312" ?>
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
      <HTML>
      <BODY>
      <CENTER>
      <TABLE BORDER="1">
      <TR>
      <TD>起始地</TD>
      <TD>目的地</TD>
      <TD>起飞时间</TD>
      <TD>到达时间</TD>
      <TD>经济仓价格</TD>
      <TD>头等仓价格</TD>  
      </TR>
      <xsl:for-each select="Air-Tickets/Ticket">
      <TR>
      <TD>
      <xsl:value-of select="From" />
      </TD>
      <TD>
      <xsl:value-of select="To" />
      </TD>
      <TD>
      <xsl:value-of select="DepartingTime" />
      </TD>
      <TD>
      <xsl:value-of select="ArrivingTime" />
      </TD>
      <TD>
      <xsl:value-of select="price" />
      </TD>
      <TD>
      <xsl:value-of select="price1" />
      </TD>
      </TR>
      </xsl:for-each>
      </TABLE>
      </CENTER>
      </BODY>
      </HTML>
      </xsl:template>
      </xsl:stylesheet>

    WebForm1.aspx.cs

    using System;

    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;

    namespace faight
    {
     /// <summary>
     /// WebForm1 的摘要说明。
     /// </summary>
     public class WebForm1 : System.Web.UI.Page
     {
      protected System.Web.UI.WebControls.Label Label1;
      protected System.Web.UI.WebControls.Label Label7;
      protected System.Web.UI.WebControls.Label Label6;
      protected System.Web.UI.WebControls.Label Label5;
      protected System.Web.UI.WebControls.Label Label4;
      protected System.Web.UI.WebControls.Label Label3;
      protected System.Web.UI.WebControls.TextBox From;
      protected System.Web.UI.WebControls.TextBox To;
      protected System.Web.UI.WebControls.TextBox DepartingTime;
      protected System.Web.UI.WebControls.TextBox ArrivingTime;
      protected System.Web.UI.WebControls.TextBox price;
      protected System.Web.UI.WebControls.TextBox price1;
      protected System.Web.UI.WebControls.Label Label2;
      protected System.Web.UI.WebControls.Label Label8;
      protected System.Web.UI.WebControls.Xml myXml;
      protected System.Web.UI.WebControls.Button Submit;
      protected System.Web.UI.WebControls.Label mudidi ;
     
      private void Page_Load(object sender, System.EventArgs e)
      {
       if(!IsPostBack)
       {
        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc.Load(Server.MapPath("tickets.xml"));
        myXml.Document = xmlDoc;
       }
      }

      #region Web 窗体设计器生成的代码
      override protected void OnInit(EventArgs e)
      {
       //
       // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
       //
       InitializeComponent();
       base.OnInit(e);
      }
      
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      private void InitializeComponent()
      {    
                                                 this.Submit.Click += new System.EventHandler(this.Submit_Click);
       this.Load += new System.EventHandler(this.Page_Load);

      }
      #endregion

      private void Submit_Click(object sender, System.EventArgs e)

      {
       XmlDocument xmlDoc =new XmlDocument();
       xmlDoc.Load(Server.MapPath("tickets.xml"));

       XmlNode xmlRoot =xmlDoc.DocumentElement;

       XmlElement xmlTicket =xmlDoc.CreateElement("Ticket");
       XmlElement xmlFrom =xmlDoc.CreateElement("From");
       XmlElement xmlTo =xmlDoc.CreateElement("To");
       XmlElement xmlDepartingTime=xmlDoc.CreateElement("DepartingTime");
       XmlElement xmlArrivingTime=xmlDoc.CreateElement("ArrivingTime");
       XmlElement xmlprice=xmlDoc.CreateElement("price");
       XmlElement xmlprice1=xmlDoc.CreateElement("price1");

       xmlFrom.InnerXml=From.Text;
       xmlTo.InnerXml=To.Text;
       xmlDepartingTime.InnerXml=DepartingTime.Text;
       xmlArrivingTime.InnerXml=ArrivingTime.Text;
       xmlprice.InnerXml=price.Text;
       xmlprice1.InnerXml=price1.Text;

       xmlTicket.AppendChild(xmlFrom);
       xmlTicket.AppendChild(xmlTo);
       xmlTicket.AppendChild(xmlDepartingTime);
       xmlTicket.AppendChild(xmlArrivingTime);
       xmlTicket.AppendChild(xmlprice);
       xmlTicket.AppendChild(xmlprice1);

                xmlRoot.AppendChild(xmlTicket);
       xmlDoc.Save(Server.MapPath("tickets.xml"));
       xmlDoc.Load(Server.MapPath("tickets.xml"));
       myXml.Document=xmlDoc;

      }

     }
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/5/17 8:04:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/29 4:03:59

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    6,482.422ms