Click here to Skip to main content
15,914,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it possible to compare the values saved in an array to the xml file located at drive c? Please help me. If it is possible, please guide me on how to code that.

Thanks. :)
Posted
Updated 25-Nov-10 18:50pm
v2
Comments
Tarun.K.S 26-Nov-10 4:58am    
yes it is possible.
Dalek Dave 26-Nov-10 5:23am    
I think he needs more help than that, Tarun! :)
Tarun.K.S 26-Nov-10 6:58am    
ohkay let me give a hint.

Assuming an xml:
XML
<pre lang="xml">
<xml version="1.0">
<Names>
<Name>Tarun</Name>
<Name>Yummy</Name>
<Name>Delicious</Name>
</Names>
</pre>


Load the Xml:

C#
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("C:\MyXml.xml");

//your array here!
String[] myArray=new String[]{"Tarun","Yummy"};

// Now search for names:

foreach(XmlNode myXmlNode in xmlDoc.Childnodes)
{
  for(int i=0;i<myarray.length;i++)>
  {
    if (myArray[i]==myXmlNode.value)
     {
      messagebox(myArray[i]);
     }
  }
}


Well its better to learn XPath if you want to go directly to Name node in the xml.
like specifying in this form:

C#
String myXPath="/Names/Name";   //it will point to all the name nodes

XmlNodeList myNodesList=xmlDoc.SelectNodes(myXPath); //Selects all Name node

then replace top portion of the above for loop with this:

C#
foreach(XmlNode myXmlNode in myNodesList)
 
Share this answer
 
v4
Comments
yummy02 26-Nov-10 22:20pm    
thanks for the help.. i'll try it now..
Ankur\m/ 27-Nov-10 4:52am    
[moved from answer]
OP wrote:
hi. I have some problem regarding Tarun's post. I assumed that myXmlNode is the xml file located at my drive c:. but it seems that myXmlNode has no value? please help me. thanks
Ankur\m/ 27-Nov-10 4:53am    
[moved from answer's comment]
Tarun K.S wrote:
myXmlNode is not an xml file. it represents the nodes of the xml.
First you need to parse XML (or may be deserialize it) and then perform the comparison.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900