473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

XML and C# methods

Hi Group,

long story short:

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)

2 - Also, I need to know which class is better to be used. System.xml or
XmlReader for search part?

Thanks in advance for your help.


Nov 15 '05 #1
3 1290
> 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...asp?frame=true

Hope this helps.
--
Jeffrey Wynn
jw***@nospam.net
"C# newbie" <rs****@otxresearch.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl... Hi Group,

long story short:

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)

2 - Also, I need to know which class is better to be used. System.xml or
XmlReader for search part?

Thanks in advance for your help.

Nov 15 '05 #2
Hi Jeffrey,

I appreciate your great help. I'm totally new to C# and XML so your help
was very helpful. Only I need to know if you have any suggestions on the
project I'm involved in.

I have to write a class using C# to parse, search and replace an XML file
tokens and data. This class should handle these :

1 -Find a data
2 -Get its parent
3 - Report its type
4 - Grab its attributes

Am I on a right track ? If I focus on System.xml namesapce. Do I need any
other information ? please let me know it. Do you suggest any book on this
or msdn help is enough ?

Thanks a lot
C# newbie


"Jeffrey Wynn" <so********@optonline.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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...asp?frame=true
Hope this helps.
--
Jeffrey Wynn
jw***@nospam.net
"C# newbie" <rs****@otxresearch.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
Hi Group,

long story short:

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)

2 - Also, I need to know which class is better to be used. System.xml or
XmlReader for search part?

Thanks in advance for your help.


Nov 15 '05 #3

I forgot to ask you: should I work with "Regex" either ?

thanks again

"Jeffrey Wynn" <so********@optonline.net> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
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...asp?frame=true
Hope this helps.
--
Jeffrey Wynn
jw***@nospam.net
"C# newbie" <rs****@otxresearch.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
Hi Group,

long story short:

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)

2 - Also, I need to know which class is better to be used. System.xml or
XmlReader for search part?

Thanks in advance for your help.


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
4
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned...
51
by: Noam Raphael | last post by:
Hello, I thought about a new Python feature. Please tell me what you think about it. Say you want to write a base class with some unimplemented methods, that subclasses must implement (or...
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
2
by: Mark | last post by:
I have it in my head that I saw a marketing document from Microsoft with the total number of classes and methods in the .NET Framework. Something like 70,000 methods? I don't need precise numbers,...
5
by: Genboy | last post by:
My "VIS" Website, which is a C# site created in VS.NET, Framework 1.1, is no longer compiling for me via the command line. As I have done 600 times in the last year and a half, I can compile to...
3
by: rickeringill | last post by:
Hi comp.lang.javascript, I'm throwing this in for discussion. First up I don't claim to be any sort of authority on the ecmascript language spec - in fact I'm a relative newb to these more...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
2
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.