Advertisement
hristo_bratanov

Extract content from .xml without the tags

Jan 26th, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4.  
  5. class ExtractContentFromXML
  6. {
  7.     static void Main()
  8.     {
  9.         StreamReader reader = new StreamReader("content.xml");
  10.         List<string> linesWithTags = new List<string>();
  11.         using (reader)
  12.         {
  13.             string line = reader.ReadLine();
  14.             while (line != null)
  15.             {
  16.                     int startTagIndex = line.IndexOf('<');    
  17.                     int endTagIndex = line.IndexOf('>', startTagIndex + 1);
  18.                     string initialLineValue = line;
  19.                     while (startTagIndex != -1)
  20.                     {
  21.                                                                                                  
  22.                         line = initialLineValue.Substring(startTagIndex, endTagIndex - startTagIndex+1);  
  23.                         startTagIndex = initialLineValue.IndexOf('<', endTagIndex + 1);
  24.                         endTagIndex = initialLineValue.IndexOf('>', startTagIndex + 1);
  25.                         linesWithTags.Add(line);
  26.                     }
  27.                            
  28.                     line = reader.ReadLine();
  29.             }
  30.            
  31.         }
  32.  
  33.         StreamWriter writer = new StreamWriter("content.xml"); //
  34.         using (writer)
  35.         {
  36.             for (int i = 0; i < linesWithTags.Count; i++)
  37.             {
  38.                 writer.Write(linesWithTags[i]);
  39.             }    
  40.         }
  41.        
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement