Click to See Complete Forum and Search --> : appendchild without adding duplicates - how?


jpassmore
02-02-2005, 12:30 PM
I have a small app that uses an existing XML document.
It does the following:

- Pulls files by label from SourceSafe
- Adds the files & some path info. for build purposes to the XML
- It then goes back and does this for each build.
ie. If build 1.00.02, it will get 1.00.00, then 1.00.01, then 1.00.02 and put the info. into the XML doc.

The problem I have is that occasionally a file is updated in two or more of the build versions, so it gets added multiple times to the XML doc. how do I check to see if the filename already exists in the node before inserting it in order to avoid duplicates?

<MACHINE>
<NAME>Server 1</NAME>
<STEPS>
- <STEP TYPE="COPYFILE">
<RELDIR />
<FILENAME>DBupdate.sql</FILENAME>
<DESTPATH>D:\install</DESTPATH>
</STEP>
- <STEP TYPE="COPYFILE">
<RELDIR />
<FILENAME>DBupdate.sql</FILENAME>
<DESTPATH>D:\install</DESTPATH>
</STEP>
</STEPS>

I don't want the above to happen. The STEP should only appear once.

Khalid Ali
02-02-2005, 06:18 PM
this will be a loose test but you can certainly look for something like

NodeList list = document.getElementsByTagName("tagName");
and then check the value for that tag.
You can alwas do another before stuff is put in xml file that is
as soon as you come accross a file name, add it to a list, then when you hit the next file name see if it already exists in the list if it does that means it had been created in xml file..etc:D

jpassmore
02-02-2005, 06:51 PM
I decided it would probably be easier to clean up my array than to do the check at insertion time.

Thanks for the response!