怎么样直接读取外网XML

t16qxz 2010-08-31 09:10:02
我现在有个地址:http://www.test.com/xml/jdxml.xml

请问用c#可以直接读出来吗?
...全文
102 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
q107770540 2010-08-31
  • 打赏
  • 举报
回复

static void Main(string[] args)
{
String URLString = "http://www.test.com/xml/jdxml.xml";
XmlTextReader reader = new XmlTextReader (URLString);

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
Console.Write("<" + reader.Name);

while (reader.MoveToNextAttribute()) // Read the attributes.
Console.Write(" " + reader.Name + "='" + reader.Value + "'");
Console.Write(">");
Console.WriteLine(">");
break;
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine (reader.Value);
break;
case XmlNodeType. EndElement: //Display the end of the element.
Console.Write("</" + reader.Name);
Console.WriteLine(">");
break;
}
}
}
sprc_lcl 2010-08-31
  • 打赏
  • 举报
回复
可以,用读网页的方法

查WebRequest 怎么用

110,534

社区成员

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

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

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