-1

I have a scenario where in a text file there are multiple xml records with some other data as well. I wrote a regex code in a foreach in c# to extract the XML.Below is the code.

foreach (Match match in Regex.Matches(File.ReadAllText(file), @"<Root>(?<sender>.*)</Root>"))
            {}

The problem I am facing is that it is not iterating on the whole file but only picking up few records.

Is there something wrong in the regex or some other problem is there.

stuartd
  • 70,509
  • 14
  • 132
  • 163
Harshit
  • 17
  • 4
  • 1
    provide a sample xml which generetes an error, please – bottaio Mar 26 '16 at 13:42
  • 1
    Is there a specific reason not to use something dedicated to parsing XML, like [LINQ to XML](https://msdn.microsoft.com/library/bb387098.aspx) for example? – Corak Mar 26 '16 at 13:50
  • [Obligatory response](http://stackoverflow.com/a/1732454/1715579). Have you tried using an XML parser instead? – p.s.w.g Mar 26 '16 at 14:00
  • The reason I am using regex is that the text file apart from XML also has date time which is not part of XML. So I am not able to pick only XML file. If some other solution is there please do let me know. – Harshit Mar 27 '16 at 12:26

1 Answers1

0

Try this,

 foreach (Match match in Regex.Matches(File.ReadAllText(file), @"<Root>[.\s]*<\/Root>"))
            {}
Venu prasad H S
  • 231
  • 1
  • 8