Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I try explain this otherwise. I need to save all nodes in first <Something> <Something> in one row. So result will be:

C#
String s = "Hello to the world"


Now I save this string into a list and move to next node:

C#
string s = "John"


Save into list and another node:

C#
string s = "January February"


Etc.
Is this even possible?
Is this explanation better?
Sorry for my english and thanks for patience

XML
<Root>
     <Something>
          <Word>Hello</Word>
          <Word>to</Word>
          <Word>the</Word>
          <Word>World</Word>
     </Something>
     <Something>
          <Word>John</Word>
     </Something>
     <Something>
          <Word>January</Word>
          <Word>February</Word>
     </Something>
</Root>
</pre>
Posted
Updated 18-Feb-15 1:42am
v5
Comments
[no name] 18-Feb-15 5:47am    
Question is not clear..
Member 11442791 18-Feb-15 6:20am    
Hi, I need to get all text between <something> and </something> as a single string. "Hello to the World".
Richard MacCutchan 18-Feb-15 6:18am    
Member 11442791 18-Feb-15 7:43am    
I updated my question. Hope now is more clearer what i mean.
TheRealSteveJudge 18-Feb-15 8:28am    
Now it is crystal clear.

 
Share this answer
 
Please have a look here:
http://www.dotnetperls.com/xmlreader[^]
 
Share this answer
 
XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace ParseXML
{
   class Program
   {
      static void Main(string[] args)
      {

         string strXMl =@"<pre lang='xml'>"
+"<Root>"+
     "<Something>"+
          "<Word>Hello </Word>"
          +"<Word>to </Word>"
          +"<Word>the </Word>"
          +"<Word>World </Word>"
     +"</Something>"
         +"<Something>"
          +"<Word>John</Word>"
     +"</Something>"
     +"<Something>"+
          "<Word>January </Word>"+
          "<Word>February</Word>"
     +"</Something>"+
"</Root>"+
"</pre>";

         XDocument Xele = XDocument.Parse(strXMl);

         foreach (var i in Xele.Descendants("Something"))
         {
            Console.WriteLine(i.Value);

         }

      }
   }
}


You can use this approach
 
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