Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to create a function that handles this (odd) stringreplacement in an XML file?

Avatar of PeterdeB
PeterdeBFlag for Netherlands asked on
4 Comments1 Solution266 ViewsLast Modified:
Hi All!

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?

Kind regards,


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.

Avatar of 2266180
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers