【发布时间】:2012-03-30 15:05:17
【问题描述】:
考虑一下我的源文件看起来像这样。
<Content xmlns="uuid:4522eb85-0a47-45f9-8e2b-1x82c78xx920">
<first>Hello World.This is Fisrt field</first>
<second>Hello World.This is second field</second>
</Content>
我想写一个代码,从一个位置读取这个 xml 文档并将其显示为字符串。
say name of the xml file is helloworld.xml.
Location: D:\abcd\cdef\all\helloworld.xml.
我尝试了以下方法,但我无法做到。
XmlDocument contentxml = new XmlDocument();
contentxml.LoadXml(@"D:\abcd\cdef\all\helloworld.xml");
Response.Write("<BR>" + contentxml.ToString());
Response.write 没有显示任何内容。如果我错过任何事情,请纠正我。它没有创建任何组件并且错误即将到来。
这个我也试过了,
XmlDocument contentxml = new XmlDocument();
try
{
contentxml.LoadXml(@"D:\abcd\cdef\all\helloworld.xml");
}
catch (XmlException exp)
{
Console.WriteLine(exp.Message);
}
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
contentxml.WriteTo(xw);
Response.Write("<BR>" + sw.ToString());
但我没有找到任何输出。
我想从某个位置读取 XML 文件并将其显示为字符串。
谁能帮忙解决这个问题。
谢谢你, 穆齐米尔。
【问题讨论】:
标签: c# asp.net xmldocument xmlreader