1- What namespace or class should I use to let me open an XML file and
then
put its content in a TextBox which is assumed as an editor ? ( Then I need
to do some search process on some tokens within it)
System.Xml, which you refer to in question 2, is the main namespace you
would use. You could load an instance of XmlDocument with the file. You
could then set the Text property of the TextBox to the OuterXml property of
the XmlDocument instance.
try {
string filepath = "path to file";
XmlDocument doc = new XmlDocument();
doc.Load( filepath );
TextBox1.Text = doc.OuterXml;
}
catch( XmlException xe ) {
// do something
}
For searching the XmlDocument, you would then use any of the following
methods of the XmlDocument (SelectNodes, SelectSingleNode,
GetElementsByTagName, etc.). The Select* methods are more powerful for
searching because they support XPath expressions.
Of course if the processing your are referring to doesn't involve XML other
than the fact that it is an XML file you are loading into the TextBox, you
could use a TextReader, part of the System.IO namespace, to read the file.
From there, use methods of the string class for searching (IndexOf,
IndexOfAny, LastIndexOf, etc.).
2 - Also, I need to know which class is better to be used. System.xml or
XmlReader for search part?
Maybe I'm misunderstanding you, but System.Xml is a namespace to which
XmlReader belongs. XmlReader provides forward-only, read-only access to a
stream of XML data. You really can't search the way you would probably like
to. To achieve searching the way you probably want it, you would first need
a loaded XML DOM. See my reply to question 1 above.
See the following link which discusses Xml in the .NET Framework.
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconemployingxmlinnetframework.asp?frame=true
Hope this helps.