认为我的源文件看起来像这样。如何读取XML文档并在c中显示字符串输出#
<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文件,并以字符串形式显示它。
任何人都可以帮忙。
谢谢, Muzimil。