Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
C#
var GetImagesList = (from x in NgDb.StagingXMLs where x.StagingLoadHistoryId == Convert.ToInt32(loadHistoryID) select x.Data).SingleOrDefault();

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.
C#
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(GetImagesList);
Posted
Updated 3-Feb-16 2:10am
v2
Comments
[no name] 3-Feb-16 8:25am    
Provide your XML data on which you want to loop over. Secondly what is value you are getting in GetImagesList variable?
Rob Philpott 3-Feb-16 11:32am    
The 'var' obscures the really rather useful type information.
raxhemanth 4-Feb-16 3:33am    
Getimageslist get the xml document from the table. so we need to loop through that xml file here.
Maciej Los 11-Feb-16 17:13pm    
What exactly GetImageList variable stores? Use debugger to find out! If it returns string of xml, you should use Parse method.
What you mean by saying you want to loop through the nodes?

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

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


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

Hogan
 
Share this answer
 
Comments
Rob Philpott 3-Feb-16 11:32am    
Seems sound to me.
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900