I have many files ".txt" files which has usual text and xml tags in the file. The file is really big and quantity of files is really high. So I want just take xml without text. I know that
tags start from
<body>
</body>
<body>
<body>
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
<body>
...
</body>
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
<body>
...
</body>
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
<body>
...
</body>
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
exampleTextexampleTextexampleTextexampleTextexampleTextexampleText
XDocument doc = XDocument.Parse(str);
Data at the root level is invalid. Line 1, position 1.
Try something like code below. It will work if all the lines start with a "<". If not we may need to use Regex.
StreamReader reader = new StreamReader(FILENAME, Encoding.UTF8); string inputLine = ""; string str = ""; while ((inputLine = reader.ReadLine()) != null) { if (inputLine.Trim().StartsWith("<")) { str += inputLine + "\n"; } }