I have the following input string which is from a 10MB text file
string data = "0x52341\n0x52341<?xml version=\"1.0\" encoding=\"UTF-8\"?><element1 value=\"3\"><sub>1</sub></element1>0x52341\n0x52341 <element1><sub><element>2</element></sub></element1>0x52341<element2><sub>3</sub></element2> <element2><sub>4</sub></element2>0x4312";
now I want this string by element1 and element2 XML nodes
the result in this case should be
output[0] = "<element1 value="3"><sub>1</sub></element1>";
output[1] = "<element1><sub><element>2</element></sub></element1>";
output[2] = "<element2><sub>3</sub></element2>";
output[3] = "<element2><sub>4</sub></element2>";
my efford:
i have tried Regular Expression but that's very slow in case of that big file and i have also tried
string[] output= input.Split(new string[] { "<element1>", "<element2>" }, StringSplitOptions.None);
string.Split() is circuitous because it throws outofmemory exceptions and the delemiter is being removed at splitting.
question: is there a easy way to parse those xml elements out of my text file?
update: I simplified my file because i couldn't post the whole 10MB file in SO - sometimes there are 0x1234 values between the xml elements sometimes not
element1andelement2)element1andelement2are valid xml