samedi 1 août 2015

Compare innertext and switch with another innertext

Guys I am completely stumped on this one.

Basically my setup is this: I am reading a text file that has some data in it, from which I've successfully extracted only the needed information.

string[] nameAnimals = new string[lines.Length];

for (int i = 0; i < lines.Length; i++)
{
nameAnimals[i] = lines[i].Substring(0, 14).TrimEnd(trimArray);
}
textBox1.Text = nameAnimals.ToString();

//textBox1 text is MonkeyElephantTigerZebra

I am calling my function like so

readingXML(nameAnimals);

And this is how it's declared

public void readingXML(string[] checkAnimals)

Then I am reading two different XML files which have the same layout, and only differ in one InnerText. (XML # 2 doesn't contain as much data as XML # 1)

<Root><!-- This is first XML -->
    <data>
        <NUMBER>1</NUMBER>
        <NAME>Monkey</NAME>
        <PRICE>1240</Price>
    </data>
<data>
        <NUMBER>2</NUMBER>
        <NAME>Tiger</NAME>
        <PRICE>2500</Price>
    </data>
<data>
        <NUMBER>3</NUMBER>
        <NAME>Elephant</NAME>
        <PRICE>4810</Price>
    </data>
<data>
        <NUMBER>4</NUMBER>
        <NAME>Zebra</NAME>
        <PRICE>5600</Price>
    </data>
</Root>



<Root><!-- This is second XML -->
        <data>
            <NUMBER>1</NUMBER>
            <NAME>Gorilla</NAME>
            <PRICE>1240</Price>
        </data>
    <data>
            <NUMBER>2</NUMBER>
            <NAME>Bengal</NAME>
            <PRICE>2500</Price>
        </data>
    </Root>
<!-- The NAME.InnerText will always be related
between these two XML's only via NUMBER.InnerText -->

Now, I want to compare my string (I am guessing somehow with string.Contains) from that text file to the NAME.InnerText from XML # 1, get it's NUMBER.InnerText, search for the NUMBER.InnerText in XML # 2, get NAME.InnerText from XML # 2 and then show it in textBox1. If for instance, the NUMBER.InnerText from XML # 1 isn't found in XML # 2, just get PRICE.InnerText from XML # 1. So that at the end I get string GorillaElephantBengalZebra

And my data in textBox1, ideally, after getting the PRICE.InnerText would be something like this, formatting doesn't matter at this point.

Gorilla - price 1240
Elephant - price 4810
Bengal - price 2500
Zebra - price 5600

I am way in over my head, or maybe I am over thinking this one.

Also, does it seem kind of a messy way so far to do what's needed ?

I've been googling for days but I am no closer to finding a solution.

Cheers

Aucun commentaire:

Enregistrer un commentaire