12
Answers

C# - Reading an XML file and comparing data

Hypeh Vipeh

Hypeh Vipeh

13y
2.4k
1
Hi guys,

I have a program made, but my coding skills are quite poor thus i am here to seek some help.

Ok this is what i have:

a program that reads in a list of files, then stores displays them into a list box, using a recursive search. when it searches all the files, it reads the data of the file and then stores it into a string.

at the moment, i have it hard coded, so it then checks an already stored set of data and checks if the data in the file it checks contains the data.

e.g. file.txt is read in, and "in football there teams have 11 men on them". it then does a check. i have already stored entries such as "teams have 11 men". the program checks if the file contains "teams have 11 men". because it does. it moves it to a listbox called "sports". 

heres a little example of a small version of the xml file:


<?xml version="1.0"?>
<References>
<sports>
<Ref type = "football">11 man team</Ref>
<Ref type = "tennis">40 love</Ref>
<Ref type = "cricket">hit a 6</Ref>
</sports>

<games>
<Ref type = "monopoly">take £200</Ref>
<Ref type = "CS">counter terrorists</Ref>
<Ref type = "fallout">collect caps</Ref>
</games>
</References>

as you can see from the above xml. i have "sports" "games". i intend to add a lot more. in each one, in sports for example it has "football", "tennis" and so on.

obviously, my program is a recursive search, so i want it to run check 1 file after the other. if that makes sense? 

i think i need it like:

for each file:

Read XML File

check if the string contains any of the data in the xml file (so it checks down the list till it finds a match)

if it matches (e.g. football matches the content of the string) then display football file name in a listbox for sports
if it matches (e.g. 40 love matches the content of the string) then it displays the file name in a list box for sports... because in the xml above, it shows its tennis, which is in the sports list. and so on.


does this make sense?

how can i go about doing this?

many thanks in advance.
Hypeh
Answers (12)