如何从 C# 中的 DATASET 对象读取 xml 数据
我只是使用此代码从 XML 文件中读取 xml 数据。它成功从文件中读取数据。我只是想知道如何从 xml 数据集中读取 SelectSingleNode 数据。
public DataSet ds =new DataSet();
public FileStream stream = null;
stream = new FileStream(schdlpath, FileMode.Open);
ds.ReadXml(stream);
//after this even if i delete the xml file it won't hamper the appliaction.
stream.Close();
//this way I can print all the data..
Console.WriteLine(ds.GetXml());
我想要的只是读取数据 像这样
public XmlDocument document = new XmlDocument();
XmlNode ht = document.DocumentElement.SelectSingleNode("/Schedule/AudioVedioPlayer/Height");
实际上我想读取xml数据并将其存储到一个变量中。
I just used this code to read xml data from an XML file.It successfully reads the data from file.I Just want to know how can I read SelectSingleNode data from an xml dataset.
public DataSet ds =new DataSet();
public FileStream stream = null;
stream = new FileStream(schdlpath, FileMode.Open);
ds.ReadXml(stream);
//after this even if i delete the xml file it won't hamper the appliaction.
stream.Close();
//this way I can print all the data..
Console.WriteLine(ds.GetXml());
All I want is to read the data
like this
public XmlDocument document = new XmlDocument();
XmlNode ht = document.DocumentElement.SelectSingleNode("/Schedule/AudioVedioPlayer/Height");
Actually I want to read the xml data and store it into a variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将数据集中的 xml 写入流中,然后使用该流将其读入 XmlDocument 对象中。从那里,您可以使用 DOM 进行导航。
现在,您是否尝试将部分数据(作为 XML)存储到变量中?或者您正在寻找高度值?如果是前者,我对你的计划没有意见。如果是后者,我假设通过查看您的 XPath 语句 (SelectSingleNode()) 您有以下内容:
DataSet: Schedule
表:音频视频播放器
属性:高度
如果我对您的设置正确,那么您可以通过深入研究数据集轻松获得所需的值。
然后您可以访问该表:
并获取值
或者您可以直接使用它
没有理由获取 XML,除非您想要 XML 的整个部分。
You can write the xml from the dataset into a stream and then use the stream to read it into an XmlDocument object. From there, you can use the DOM to navigate.
Now, are you trying to store a part of the data, as XML, into a variable? Or are you looking for the height value? If the former, I have no issue with your plan. If the later, I assume, from looking at your XPath statement (SelectSingleNode()) that you have the following:
DataSet: Schedule
Table: AudioVedioPlayer
Property: Height
If I am correct about your setup, then you can easily get to the value you require by drilling down into the DataSet.
You can then get to the table:
And get the value
Or you can just shortcut it
No reason to get XML unless you want an entire section of XML.