I have this xml file which looks like this:
<?xml version="1.0" ?>
- <!-- LibraryPreferences.
- <!-- Created: Sun Dec 03 15:26:37 2006
- <LibraryPreferences curFolder="4" previewNum="100" limitPreview="0" doubleClickReplace="0">
- <ContentFolder folder="Runtime\libraries" index="0">
<Library libraryType="2" curLibraryFolder="character" />
<ContentFolder folder="Downloads\Runtime\libraries" index="1" />
<ContentFolder folder="K:\_Personal\_Victoria 4\Runtime\Libraries" index="2" />
<ContentFolder folder="K:\_Personal\Victoria 4\Runtime\Libraries" index="3" />
- <ContentFolder folder="K:\_Personal\Victoria 4\Runtime\Libraries" index="4">
<Library libraryType="2" curLibraryFolder="character\Delphi" />
Now I'd like to have a function which is able to insert this line:
<ContentFolder folder="K:\_Personal\Victoria 4\Runtime\Libraries" index="@" />
Into location: #....# while incrementing @. So it should determine the position as well as the last index that exists in the file. It shoudl also be able to determine whether the last "indexed line" has a child item and if so, it should skip that line and insert the new line after the child item. If it finds no child item, it should insert the new line right after the parent item i.e. the indexed item.
Can someone write such a function? I went through the XML thingie today and I managed to validate an XML file I even managed to treeview it but that's where the XML adventure ended so to speak.
I then opened up the file with notepad and added the line manually, fired up the program that uses it and it worked! So now I figured it should be possible to insert a line without too much trouble and perhaps without having to deal with the XML thingie.
I mean it should be possible to determine the position where the line should be inserted and prior to that format the line properly...right?
Ps if this all seems too abacadabra please ask for more info. Btw I tried to save a simple text file using the XML text I posted here and saving it with .xml extension instead of .txt. This seems to work okay so thats why I would like to treat this matter as a string replacement.