c# - xpath select inner text of an element which is repeated in random area of a xml file -


I have an XML file like anytime letter cases . I am interested in those elements which are inside and ... and if there is an element in a epithelium then I do not want to count it.

  & lt; Document & gt; & Lt; Test & gt; & Lt; Groups & gt; & Lt; Number & gt; & Lt; Random & gt; .... .... & lt; Pin & gt; & Lt; Pin & gt; & Lt; Number & gt; 1 & lt; / Number & gt; & Lt; / Pin & gt; & Lt; Pin & gt; & Lt; Number & gt; 2 & lt; / Number & gt; & Lt; Results & gt; & Lt; Number & gt; Not interested & lt; / Number & gt; & Lt; / Results & gt; & Lt; / Pin & gt; & Lt; / Pins & gt; & Lt; / Random & gt; & Lt; / Number & gt; & Lt; / Groups & gt;  

Code> Public Ink GetNumberOfAllPins () {string xpath = "count (/ document // pin / pin / number)"; Int num = convert toInt32 (nav.Evaluate (xpath)); Return number; } Public string [] GetNameOfAllPins () {string [] temp = new string [GetNumberOfAllPins ()]; XPathNodeIterator it = nav.Select ("/ document // pin / pin / number"); Int i = 0; While (it.MoveNext ()) {temp [i] = it.Current.Value; I ++; } Return temporary; }

But these codes give me strange results sometimes, at least or more elements that I am interested in. Will you keep some tips in mind?

Thank you.

Sorry to bother, but I bend the problem. My XML file contained some adjacent elements. This code works well!

Comments