• OnlyForTest


    public static String NextToken(StreamReader stream)
            
    {
                
    int temp = stream.Read();
                String t1 
    = "";
                
    while(temp != -1 && temp != (int)'|')
                
    {
                    t1 
    += (char)temp;
                    temp 
    = stream.Read();
                }


                
    return t1;

            }


            
    private void XmlWriteTest()
            
    {                            
                
                XmlTextWriter writer 
    = new XmlTextWriter (this.fileName, null);
                
    //Use indenting for readability.
                writer.Formatting = Formatting.Indented;
            
                writer.WriteComment(
    "sample XML fragment");
        
                
    //Write an element (this one is the root).
                writer.WriteStartElement("bookstore");

                
    //Write the namespace declaration.

                writer.WriteAttributeString(
    "xmlns""bk"null"urn:samples");
                

                writer.WriteStartElement(
    "book");

                
    //Lookup the prefix and then write the ISBN attribute.
                string prefix = writer.LookupPrefix("urn:samples");
                writer.WriteStartAttribute(prefix, 
    "ISBN""urn:samples");
                writer.WriteString(
    "1-861003-78");
                writer.WriteEndAttribute();     

                
    //Write the title.
                writer.WriteStartElement("title");
                writer.WriteString(
    "The Handmaid's Tale");
                writer.WriteEndElement();
                  
                
    //Write the price.
                writer.WriteElementString("price""19.95");
         
                
    //Write the style element.
                writer.WriteStartElement(prefix, "style""urn:samples");
                writer.WriteString(
    "hardcover");
                writer.WriteEndElement();

                
    //Write the end tag for the book element.
                writer.WriteEndElement();

                
    //Write the close tag for the root element.
                writer.WriteEndElement();
                 
                
    //Write the XML to file and close the writer.
                writer.Flush();
                writer.Close();

                
    //Read the file back in and parse to ensure well formed XML.
                XmlDocument doc = new XmlDocument();
                
    //Preserve white space for readability.
                doc.PreserveWhitespace = true;
                
    //Load the file
                doc.Load(this.fileName);
        
                
    //Write the XML content to the console.
                this.richTextBox1.Text=doc.InnerXml;

            }

            
    private void button1_Click(object sender, System.EventArgs e)
            
    {
              
    this.XmlWriteTest();
            }


            
    /// <summary>
            
    /// Load Xml files in LocalDisk
            
    /// </summary>

            private void LoadXMLFromDisk()
            
    {
                XmlDocument xmlDoc 
    =new XmlDocument();
                xmlDoc.Load(
    this.fileName);
                
    this.richTextBox1.Text=xmlDoc.DocumentElement.Prefix +"/"+xmlDoc.DocumentElement.NamespaceURI +"/"+xmlDoc.DocumentElement.Name +"/"+xmlDoc.DocumentElement.LocalName;
                
    this.richTextBox1.Text=this.richTextBox1.Text+xmlDoc.DocumentElement.SelectSingleNode("//title").InnerText +"/" +xmlDoc.DocumentElement.SelectSingleNode("//price").InnerText;
            }

            
    private void button2_Click(object sender, System.EventArgs e)
            
    {
                
    this.LoadXMLFromDisk();
            }

    本文来自博客园,作者:Slashout,转载请注明原文链接:https://www.cnblogs.com/SlashOut/archive/2005/03/24/125215.html 关注公众号:数字化转型

  • 相关阅读:
    Android 实现Path2.0中绚丽的的旋转菜单
    Android SQLite数据库增删改查操作
    Android addRule()
    Android 实现全屏、无标题栏
    微信公众号开发教程
    HEAP CORRUPTION DETECTED
    Introduction to gaussian filter 高斯滤波器
    Windows 7硬盘安装CentOS 6.4 双系统 (WIN7硬盘安装Linux(Fedora 16,CentOS 6.2,Ubuntu 12.04))
    使用Scala操作Mongodb
    数字三角——递归、递归、内存搜索
  • 原文地址:https://www.cnblogs.com/SlashOut/p/125215.html
Copyright © 2020-2023  润新知