I'm not the best english speaker, so I hope I'll be understandable.
I'm looking for the best way to replace a line in a multiline string.
I know that in my case, handling it as an xml may be easier, but sadly I can't for different reasons, I've to consider my string just as a mulitline string with a xml syntax.
First of all, I've to find the select_numserie
line I want to replace. For this I've just the hote_carte
attribute.
In my head, I would copy in another string everything before the substring I wanna replace, then I insert my new line and I copy what's after my substring. But I've no idea how to do this... And no idea how to find the substring I wanna replace..
Here's a string example :
<NewDataSet>
<Hote>
<nbpassage_numseries />
<select_numserie />
<hote_id>3348</hote_id>
<hote_carte>265</hote_carte>
<hote_elenom>AAA</hote_elenom>
<hote_elepre>Aid2 Aethys1</hote_elepre>
<division_divcod>6e1_1</division_divcod>
<regime_lib>DP</regime_lib>
<hote_carte_codee>32855869</hote_carte_codee>
</Hote>
<Hote>
<nbpassage_numseries />
<select_numserie />
<hote_id>3347</hote_id>
<hote_carte>266</hote_carte>
<hote_elenom>AAA</hote_elenom>
<hote_elepre>Aidé Aethys2</hote_elepre>
<division_divcod>6e1_1</division_divcod>
<regime_lib>DP</regime_lib>
<hote_carte_codee>40616617</hote_carte_codee>
</Hote>
<Hote>
<nbpassage_numseries />
<select_numserie />
<hote_id>3349</hote_id>
<hote_carte>7777</hote_carte>
<hote_elenom>AAA</hote_elenom>
<hote_elepre>Aidx</hote_elepre>
<division_divcod>TEST GHISLAIN</division_divcod>
<regime_lib>Externe</regime_lib>
<hote_carte_codee>33047084</hote_carte_codee>
</Hote>
<Hote>
<nbpassage_numseries />
<select_numserie />
<hote_id>3283</hote_id>
<hote_carte>7778</hote_carte>
<hote_elenom>AAA</hote_elenom>
<hote_elepre>Elva</hote_elepre>
<division_divcod>TEST GHISLAIN</division_divcod>
<regime_lib>DP</regime_lib>
<hote_carte_codee>45390356</hote_carte_codee>
</Hote>
<Hote>
<nbpassage_numseries />
<select_numserie />
<hote_id>3284</hote_id>
<hote_carte>267</hote_carte>
<hote_elenom>AAA</hote_elenom>
<hote_elepre>Elvb</hote_elepre>
<division_divcod>6e2</division_divcod>
<regime_lib>Externe</regime_lib>
<hote_carte_codee>23722768</hote_carte_codee>
</Hote>
[...]
</NewDataSet>
[EDIT]
It is this line : <select_numserie />
I want to replace.
For exemple, if I have 7778 as parameter,, I've to replace the <select_numserie />
line, in the Hote
node, where hote_carte
== 7778. And I will replace this by <select_numserie> [timestamp value, this value is given in parameter] </select_numserie>
And in the case where the select_numserie
value is already written, then I've to remove the value.
And all of this, without using any XML property or whatever. Just consider the string as a string with an xml syntax.