OnlyForTest

None.gif public   static  String NextToken(StreamReader stream)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
int temp = stream.Read();
InBlock.gif            String t1 
= "";
InBlock.gif            
while(temp != -1 && temp != (int)'|')
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                t1 
+= (char)temp;
InBlock.gif                temp 
= stream.Read();
ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
return t1;
InBlock.gif
ExpandedBlockEnd.gif        }

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

InBlock.gif            writer.WriteAttributeString(
"xmlns""bk"null"urn:samples");
InBlock.gif            
InBlock.gif
InBlock.gif            writer.WriteStartElement(
"book");
InBlock.gif
InBlock.gif            
//Lookup the prefix and then write the ISBN attribute.
InBlock.gif
            string prefix = writer.LookupPrefix("urn:samples");
InBlock.gif            writer.WriteStartAttribute(prefix, 
"ISBN""urn:samples");
InBlock.gif            writer.WriteString(
"1-861003-78");
InBlock.gif            writer.WriteEndAttribute();     
InBlock.gif
InBlock.gif            
//Write the title.
InBlock.gif
            writer.WriteStartElement("title");
InBlock.gif            writer.WriteString(
"The Handmaid's Tale");
InBlock.gif            writer.WriteEndElement();
InBlock.gif              
InBlock.gif            
//Write the price.
InBlock.gif
            writer.WriteElementString("price""19.95");
InBlock.gif     
InBlock.gif            
//Write the style element.
InBlock.gif
            writer.WriteStartElement(prefix, "style""urn:samples");
InBlock.gif            writer.WriteString(
"hardcover");
InBlock.gif            writer.WriteEndElement();
InBlock.gif
InBlock.gif            
//Write the end tag for the book element.
InBlock.gif
            writer.WriteEndElement();
InBlock.gif
InBlock.gif            
//Write the close tag for the root element.
InBlock.gif
            writer.WriteEndElement();
InBlock.gif             
InBlock.gif            
//Write the XML to file and close the writer.
InBlock.gif
            writer.Flush();
InBlock.gif            writer.Close();
InBlock.gif
InBlock.gif            
//Read the file back in and parse to ensure well formed XML.
InBlock.gif
            XmlDocument doc = new XmlDocument();
InBlock.gif            
//Preserve white space for readability.
InBlock.gif
            doc.PreserveWhitespace = true;
InBlock.gif            
//Load the file
InBlock.gif
            doc.Load(this.fileName);
InBlock.gif    
InBlock.gif            
//Write the XML content to the console.
InBlock.gif
            this.richTextBox1.Text=doc.InnerXml;
InBlock.gif
ExpandedBlockEnd.gif        }

None.gif        
private   void  button1_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif          
this.XmlWriteTest();
ExpandedBlockEnd.gif        }

None.gif
ExpandedBlockStart.gifContractedBlock.gif        
/**/ /// <summary>
InBlock.gif        
/// Load Xml files in LocalDisk
ExpandedBlockEnd.gif        
/// </summary>

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

None.gif        
private   void  button2_Click( object  sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
this.LoadXMLFromDisk();
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/SlashOut/archive/2005/03/24/125215.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值