XmlTextReader VS XmlDocument

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Samishii23
    New Member
    • Sep 2009
    • 246

    XmlTextReader VS XmlDocument

    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?
  • Samishii23
    New Member
    • Sep 2009
    • 246

    #2
    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...
    Code:
    try {
      XMLClassData = new XmlTextReader(uri);
      while (XMLClassData.Read()) {
        IsTagDisc = false;
        switch (XMLClassData.NodeType) {
          case XmlNodeType.Element:
            if (XMLClassData.Name == "Talent") {
              while (XMLClassData.MoveToNextAttribute()) {
                switch (XMLClassData.Name) {
                  case "pts":
                    if (XMLClassData.Value == "0") {
                      TalentDataAtr[TDi] = "none";
                      TalentDataDisc[TDi] = "none";
                      break; }
                    else {
                      TalentDataAtr[TDi] += "pts:" + XMLClassData.Value; }
                    break;
                  case "title":
                    TalentDataAtr[TDi] += ",title:" + XMLClassData.Value; break;
                  case "icon":
                    TalentDataAtr[TDi] += ",icon:" + XMLClassData.Value; break;
                  case "req":
                    TalentDataAtr[TDi] += ",req:" + XMLClassData.Value; break;
                  }
                }
              }
            if (XMLClassData.Name == "disc") {
              IsTagDisc = true;
              if (XMLClassData.AttributeCount < 0) {
                while (XMLClassData.MoveToNextAttribute()) {
                  switch (XMLClassData.Name) {
                    case "replace": TalentDataDisc[TDi] += XMLClassData.Value + "|||"; break;
                    }
                  }
                }
              }
              break;
            case XmlNodeType.Text:
              if (IsTagDisc) {
                TalentDataDisc[TDi] += XMLClassData.Value; }
              break;
            }
          TDi++;
        }
      }
      catch (Exception EX) {
        MessageBox.Show("Problem: " + EX.Message); }

    But seriously... Theres got to be a better way to do this... =\

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      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.

      Comment

      • Samishii23
        New Member
        • Sep 2009
        • 246

        #4
        Thanks for the suggestion. I'll look into it.

        Comment

        Working...