Skip to content

Divide into parts a text or stream

Diogo

Asked May 5, 2008, 6:42 AM EDT1 answer
Share
LinkedInX
I want to divide into parts a stream, a text. I explain: I have a xml file, desire that it be uploaded to stream (already done) but now I want to divide into parts when the tag <product> appears AND save to variables or an array:

<product>
<a001>200702060470023090</a001>
<a002>03</a002>
<productidentifier>
<b221>02</b221>
<b244>0470023090</b244>
</productidentifier>
</product>
<product>
<othertext>
<d102>18</d102>
<d103>02</d103>
</othertext>
</product>


In this case two parts but the entire xml file has much more!

I tried: string[] producto = str.Split('<product>');
But error... :-(

Thanks in advanced!

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Well, easy!

    while (!sr.EndOfStream)
    {
        str = sr.ReadLine();
        Regex regex = new Regex("<product>");
        products = regex.Split(str);
    }


    I founded this soluction!
    0