将XML文件读入XmlDocument [英] Read XML file into XmlDocument

查看:53
本文介绍了将XML文件读入XmlDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C#非常陌生.我有XML文件(text.xml).我想在 XmlDocument 中阅读该内容,并将流存储在字符串变量中.

I am very new to C#. I have XML file (text.xml). I want to read that in XmlDocument and store the stream in string variable.

推荐答案

使用 XmlDocument.Load()方法从文件中加载XML.然后使用 XmlDocument.InnerXml 属性获取XML字符串.

Use XmlDocument.Load() method to load XML from your file. Then use XmlDocument.InnerXml property to get XML string.

XmlDocument doc = new XmlDocument();
doc.Load("path to your file");
string xmlcontents = doc.InnerXml;

这篇关于将XML文件读入XmlDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆