473,473 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlTextReader VS XmlDocument

Samishii23
246 New Member
I've been putting together a reader with XmlTextReader, while doing some research, I came across a couple things showing XmlDocument examples.

I was wondering what people think? Is one better then the other or more effiecient?
Feb 2 '10 #1
3 4144
Samishii23
246 New Member
I was really wondering because I typed out a a method to load a XML file...
Assuming All the proper things are in place for this to work. Since this does compile...
Expand|Select|Wrap|Line Numbers
  1. try {
  2.   XMLClassData = new XmlTextReader(uri);
  3.   while (XMLClassData.Read()) {
  4.     IsTagDisc = false;
  5.     switch (XMLClassData.NodeType) {
  6.       case XmlNodeType.Element:
  7.         if (XMLClassData.Name == "Talent") {
  8.           while (XMLClassData.MoveToNextAttribute()) {
  9.             switch (XMLClassData.Name) {
  10.               case "pts":
  11.                 if (XMLClassData.Value == "0") {
  12.                   TalentDataAtr[TDi] = "none";
  13.                   TalentDataDisc[TDi] = "none";
  14.                   break; }
  15.                 else {
  16.                   TalentDataAtr[TDi] += "pts:" + XMLClassData.Value; }
  17.                 break;
  18.               case "title":
  19.                 TalentDataAtr[TDi] += ",title:" + XMLClassData.Value; break;
  20.               case "icon":
  21.                 TalentDataAtr[TDi] += ",icon:" + XMLClassData.Value; break;
  22.               case "req":
  23.                 TalentDataAtr[TDi] += ",req:" + XMLClassData.Value; break;
  24.               }
  25.             }
  26.           }
  27.         if (XMLClassData.Name == "disc") {
  28.           IsTagDisc = true;
  29.           if (XMLClassData.AttributeCount < 0) {
  30.             while (XMLClassData.MoveToNextAttribute()) {
  31.               switch (XMLClassData.Name) {
  32.                 case "replace": TalentDataDisc[TDi] += XMLClassData.Value + "|||"; break;
  33.                 }
  34.               }
  35.             }
  36.           }
  37.           break;
  38.         case XmlNodeType.Text:
  39.           if (IsTagDisc) {
  40.             TalentDataDisc[TDi] += XMLClassData.Value; }
  41.           break;
  42.         }
  43.       TDi++;
  44.     }
  45.   }
  46.   catch (Exception EX) {
  47.     MessageBox.Show("Problem: " + EX.Message); }

But seriously... Theres got to be a better way to do this... =\
Feb 2 '10 #2
Curtis Rutland
3,256 Recognized Expert Specialist
There's a much better way in my opinion:
LINQ to XML. Look it up, it's amazing.

But the difference between an XmlTextReader and an XmlDocument is that the TextReader is a StreamReader that is made specially for XML. It is designed to open a file and read it. An XmlDocument is a Data Structure designed to hold XML data in memory.
Feb 2 '10 #3
Samishii23
246 New Member
Thanks for the suggestion. I'll look into it.
Feb 2 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Meir S. | last post by:
I think the following is a bug in XmlTextReader: I need to process large XMLs, that are typically constructed of many small elements nested in the root element. Each inner element represents a...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
5
by: Geoff Bennett | last post by:
While parsing an XML document, my TextReader instance skips nodes. For example, in this fragment: <Person Sex="Male" FirstHomeBuyer="No" YearsInCurrentProfession="14"> <RelatedEntityRef...
7
by: SQLScott | last post by:
I have a Web Service in which I am trying to pass an XMLDocument as a parameter to one of the methods. I would like to use the XMLTextReader to read the XML but I am getting the following error: ...
1
by: Emsi | last post by:
Hello, how can I read values of child nodes with the XmlTextReader? File format: <root> <items> <item> <field1>value1</field1> <field2>value2</field2>
1
by: soupaman | last post by:
Im trying to output some filtered xml using the xmlTextReader I know the code and commenting needs cleaned up and eventually plan to add the values to a dataset. currently what this is doing is...
3
by: MFRASER | last post by:
I am trying to import some data into my objects and I have been using XMLDoc.LoadXML(file), but someone told me that this is very memory intensive that if I am reading a text file that I would be...
17
by: Slonocode | last post by:
Is there any relation between the NodeType and the Text when using the XmlTextReader? The documentation uses select/case while using the xmltextreader. While reader.Read() Select Case...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
4
by: CodeRazor | last post by:
I am trying to use an XmlTextReader to retrieve data. I need to use an XmlTextReader because it is faster than using an XmlDocument. I have found an inelegant way of retrieving each item's title...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.