如何遍历以下xml文件中的每个节点? [英] How to loop through each node in the following xml file ?

查看:154
本文介绍了如何遍历以下xml文件中的每个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从数据库获取xml文档的linq查询,我想循环遍历文件中的每个节点。怎么做?

this is the linq query which gets the xml document from database and i would like to loop through each node in the file. how to do it?

var GetImagesList = (from x in NgDb.StagingXMLs where x.StagingLoadHistoryId == Convert.ToInt32(loadHistoryID) select x.Data).SingleOrDefault();



x.Data是我获取xml文件的列。



怎么办?我试图以这种方式做,但它没有将GetImagesList作为参数。


x.Data is the column where i get xml file.

How to do it? i tried to do in this way but it is not taking the GetImagesList as a parameter.

XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(GetImagesList);

推荐答案

尝试其他Load for XmlDocument。下面的一个字符串将其转换为XML文档。



Try the other Load for XmlDocument. The one below takes a string and converts it to an XML document.

XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(GetImagesList);





XmlDocument.LoadXml方法(字符串)(System.Xml) [ ^ ]



Hogan



XmlDocument.LoadXml Method (String) (System.Xml)[^]

Hogan


也许用于遍历所有节点的最佳解析方法是使用类 System。 Xml.XmlReader

XmlReader类(System.Xml) [ ^ ]。



查看此页面上的代码示例,首先,带有的那个(reader.Read()){/ * ... * /} 。这是您遍历所有节点的方式。此外,这种方法可能是最快的。



-SA
Perhaps the best method of parsing used to traverse all the node is using the class System.Xml.XmlReader:
XmlReader Class (System.Xml)[^].

Look at the code samples on this page, first of all, the one with while (reader.Read()) { /* ... */ }. This is how you traverse all the nodes. Besides, this approach is probably the fastest.

—SA


这篇关于如何遍历以下xml文件中的每个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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