Returning the first possible node's inner text in a XML file

bernardkiev

New Member
I wrote a method that specificly searches for a given full \[code\]xpath\[/code\] and returns the inner text. But since the files I am working on all have unique node names, I want to do it somehow that only passing the node name do the job.How my code looks like at the moment:\[code\]public string FileInfo(string info){ switch (info) { //FileInfo case "fileCreator": fileCreator = ztr.SelectSingleNode("//Document/FileInfo/Creator").InnerText; return fileCreator; case "fileName": fileName = ztr.SelectSingleNode("//Document/FileInfo/Name").InnerText; return fileName; //And so on with lots of other cases!!!\[/code\]How can I make it somehhow that it searches for the first occurance of \[code\]info\[/code\] string that is a xml node so I dont have to be stupid and write all these switch statements...UPDATEplease note not all the stuff I want are located in \[code\]FileInfo\[/code\] node...I want the method to search for the node I pass to it! Or better to say I want to pass the name of the node itself into this method and get its value. Sorry if I was confusing prior to this edit!some more examples in the xml file:\[code\]/Document/RuntimeInfo/Operator\[/code\]So I want to pass in "Operator" into my method and I get its value! should be up to the method to discover the correct path. the pats are unique so it wouldnt be a bad idea to implement this method.
 
Back
Top