请教在C#中 如何读流

wysxm002 2004-08-29 11:53:53
如何在XML中读流 请给代码事例
...全文
142 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunkangta 2004-09-13
  • 打赏
  • 举报
回复
FileStream
StreamWriter
StreamReader
chikinglau 2004-09-13
  • 打赏
  • 举报
回复
支持zhzuo(秋枫)
aQ44 2004-09-13
  • 打赏
  • 举报
回复
发错贴。sorry
aQ44 2004-09-13
  • 打赏
  • 举报
回复
从中只能说明微软财大气粗。。。
至于效率嘛,说真话可能很多人会吊我,说假话嘛,我不会!
khpcg 2004-08-30
  • 打赏
  • 举报
回复
VS中的帮助里有的
khpcg 2004-08-30
  • 打赏
  • 举报
回复
支持楼上的
bitsbird 2004-08-29
  • 打赏
  • 举报
回复
msdn上查
FileStream
StreamReader
marvelstack 2004-08-29
  • 打赏
  • 举报
回复
abstract class XmlReader

XmlTextReader 继承至 XmlReader
using System;
using System.IO;
using System.Xml;

public class Sample {

private const String filename = "items.xml";

public static void Main() {

XmlTextReader reader = null;

try {

// Load the reader with the data file and ignore all white space nodes.
reader = new XmlTextReader(filename);
reader.WhitespaceHandling = WhitespaceHandling.None;

// Parse the file and display each of the nodes.
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element:
Console.Write("<{0}>", reader.Name);
break;
case XmlNodeType.Text:
Console.Write(reader.Value);
break;
case XmlNodeType.CDATA:
Console.Write("<![CDATA[{0}]]>", reader.Value);
break;
case XmlNodeType.ProcessingInstruction:
Console.Write("<?{0} {1}?>", reader.Name, reader.Value);
break;
case XmlNodeType.Comment:
Console.Write("<!--{0}-->", reader.Value);
break;
case XmlNodeType.XmlDeclaration:
Console.Write("<?xml version='1.0'?>");
break;
case XmlNodeType.Document:
break;
case XmlNodeType.DocumentType:
Console.Write("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
break;
case XmlNodeType.EntityReference:
Console.Write(reader.Name);
break;
case XmlNodeType.EndElement:
Console.Write("</{0}>", reader.Name);
break;
}
}
}

finally {
if (reader!=null)
reader.Close();
}
}
} // End class
[Visual Basic, C#] 该示例使用文件 items.xml。
<?xml version="1.0"?>
<!-- This is a sample XML document -->
<!DOCTYPE Items [<!ENTITY number "123">]>
<Items>
<Item>Test with an entity: &number;</Item>
<Item>test with a child element <more/> stuff</Item>
<Item>test with a CDATA section <![CDATA[<456>]]> def</Item>
<Item>Test with an char entity: A</Item>
<!-- Fourteen chars in this element.-->
<Item>1234567890ABCD</Item>
</Items>

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧