虎克的博客

Enthusiasm Biogeography-Biodiversity Informatics-Data Sciences

XML学习笔记(五):读写非文本格式的XML文件

| Comments

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NonTextDataXML.aspx.cs" Inherits="NonTextDataXML" %>

 

<!DOCTYPE html PUBLIC "–//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>

<html xmlns="http://www.w3.org/1999/xhtml&quot;>

<head runat="server">

    <title></title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        Image file name:

        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

        Target XML file name:

        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

        <br />

        <asp:Button ID="Button1" runat="server" Text="Save images as XML" OnClick="Button1_Click" />

        <asp:Button ID="Button2" runat="server" Text="Validation Output" OnClick="Button2_Click" />

        <br />

        <asp:ImageButton ID="ImageButton1" runat="server" Height="230px" Width="155px" />

    </div>

    </form>

</body>

</html>

执行代码:

   1:  using System;

   2:  using System.Web.UI.WebControls;

   3:  using System.Xml;

   4:  using System.IO;

   5:   

   6:   

   7:   

   8:  public partial class NonTextDataXML : System.Web.UI.Page

   9:  {

  10:      protected void Page_Load(object sender, EventArgs e)

  11:      {

  12:   

  13:      }

  14:      /// <summary>

  15:      /// Handles the Click event of the Button1 control.

  16:      /// </summary>将图片文件存储为XML文件格式(串行化)

  17:      /// The code creates an XmlTextWriter object by passing the path of the destination XML file to the constructor. 

  18:      /// Then a FileStream is created for reading data from the image file. The contents of the file are read by using the Read() method of the FileStream class, which accepts three parameters: the byte array to read the data into, the start index in the byte array from where the writing should start, and the length of data to read. 

  19:      /// The XmlTextWriter then starts writing the document. It first writes the XML processing instruction and the <imagefile> element. The <imagefile> element has two attributes: filename and s

   original link:
   <a href='http://Apiaceae.github.io/blog/2009/05/10/XML%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%28%E4%BA%94%29%3A%E8%AF%BB%E5%86%99%E9%9D%9E%E6%96%87%E6%9C%AC%E6%A0%BC%E5%BC%8F%E7%9A%84XML%E6%96%87%E4%BB%B6/'>http://Apiaceae.github.io/blog/2009/05/10/XML%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%28%E4%BA%94%29%3A%E8%AF%BB%E5%86%99%E9%9D%9E%E6%96%87%E6%9C%AC%E6%A0%BC%E5%BC%8F%E7%9A%84XML%E6%96%87%E4%BB%B6/</a><br/>
   &nbsp;written by <a href='http://Apiaceae.github.io'>Hooker</a>
   &nbsp;posted at <a href='http://Apiaceae.github.io'>http://Apiaceae.github.io</a>
   </p>

Comments