0

I'm trying toloop the below code in c# and getting count = 0

I was doing as below code

 foreach (XmlNode intraday_series in source_file.DocumentElement.SelectNodes("//IntradayStructuring "))
      {
      }

But still intraday_series is 0

xml

Rahul
  • 5,603
  • 6
  • 34
  • 57
user1990395
  • 185
  • 1
  • 13
  • 4
    You are missing the namespace. So that's reason why result == 0. – Toan Vo May 13 '13 at 11:00
  • http://stackoverflow.com/questions/14370989/which-xpath-expression-will-allow-me-to-select-these-nodes – JLRishe May 13 '13 at 11:01
  • you have a trailing space in the XPath Query. Did you check it – Saravanan May 13 '13 at 11:04
  • The file has XMLSchema namespace and the file was saved as xml rather than xsd then...? While loading the file I can add xml namespace and do you think that should work? – user1990395 May 13 '13 at 11:04
  • Also, are you able to get the list of elements by applying this Xpath in the quick watch or immediate window. – Saravanan May 13 '13 at 11:05
  • Your IntradayStructuring elements are in the namespace `urn:schemas-microsoft-com:sql:SqlRowSet1`. You need to use an XmlNamespaceManager to assign a prefix to that namespace and then refer to the elements with that prefix. Please see the link I already posted above. – JLRishe May 13 '13 at 11:09
  • @saravanan I was getting all the data in innerxml but i don't need in that way. I need to loop each node and get the values.But the selectNodes doesn't retrieve anything and count is 0 – user1990395 May 13 '13 at 11:09
  • @JLRishe yeah I was looking into that mate – user1990395 May 13 '13 at 11:11
  • @JLRishe what should I can add this line in my case..? m.AddNamespace("myns", "url1"); – user1990395 May 13 '13 at 11:12
  • @user1990395: did you remove the space in the xpath query. – Saravanan May 13 '13 at 11:18
  • @JLRishe Thanks for the link got it in the loop.. cheers mate – user1990395 May 13 '13 at 11:23

0 Answers0