Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. open two XmlDocuments at same time

open two XmlDocuments at same time

Scheduled Pinned Locked Moved XML / XSL
questionxml
6 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I need process two nodelists. so I have to open two XmlDocuments at the same time. Why does this code crash? string filename = "D:\test.xml"; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList nl = doc.SelectNodes("TestSequence"); string filenameOpt = "D:\Options.xml"; XmlDocument docOpt = new XmlDocument(); docOpt.LoadXml(filename); readXML(nl);

    M 1 Reply Last reply
    0
    • A Anonymous

      Hi, I need process two nodelists. so I have to open two XmlDocuments at the same time. Why does this code crash? string filename = "D:\test.xml"; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList nl = doc.SelectNodes("TestSequence"); string filenameOpt = "D:\Options.xml"; XmlDocument docOpt = new XmlDocument(); docOpt.LoadXml(filename); readXML(nl);

      M Offline
      M Offline
      Mark Smithson
      wrote on last edited by
      #2

      One thing that is wrong is that the filename strings are not properly escaped. Try changing string filename="D:\test.xml" to string filename=@"D:\test.xml" or string filename=@"D:\\test.xml" You will also need to do the same for "D:\Options.xml" "\t" will translate to a tab character, which will cause the load of the first document to fail as it can not find the file, or possibly that the filename is invalid. Another problem is that when you are loading the second document you are using LoadXml and not Load. "D:\Options.xml" is not a valid xml string. I have made both these mistakes far too many times myself :wtf: Regards Mark Smithson

      A 1 Reply Last reply
      0
      • M Mark Smithson

        One thing that is wrong is that the filename strings are not properly escaped. Try changing string filename="D:\test.xml" to string filename=@"D:\test.xml" or string filename=@"D:\\test.xml" You will also need to do the same for "D:\Options.xml" "\t" will translate to a tab character, which will cause the load of the first document to fail as it can not find the file, or possibly that the filename is invalid. Another problem is that when you are loading the second document you are using LoadXml and not Load. "D:\Options.xml" is not a valid xml string. I have made both these mistakes far too many times myself :wtf: Regards Mark Smithson

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        thanks for your fast help!! but i made an incomplete request - sorry you were of course right but my problem appears after i load my 2nd XmlDocument (see now a completer version) string filename = @"D:\test.xml"; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList nl = doc.SelectNodes("TestSequence"); string filenameOpt = @"D:\Options.xml"; XmlDocument docOpt = new XmlDocument(); docOpt.Load(filenameOpt); //crash :( readXML(nl);

        M 1 Reply Last reply
        0
        • A Anonymous

          thanks for your fast help!! but i made an incomplete request - sorry you were of course right but my problem appears after i load my 2nd XmlDocument (see now a completer version) string filename = @"D:\test.xml"; XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList nl = doc.SelectNodes("TestSequence"); string filenameOpt = @"D:\Options.xml"; XmlDocument docOpt = new XmlDocument(); docOpt.Load(filenameOpt); //crash :( readXML(nl);

          M Offline
          M Offline
          Mark Smithson
          wrote on last edited by
          #4

          Have you made sure that the second document is valid xml? The best way to do this would be to load the document in internet explorer. You will get an error if the document is not valid. What exception message are you getting when the code crashes? This can usually lead you to the source of the problem. Regards Mark Smithson

          A 2 Replies Last reply
          0
          • M Mark Smithson

            Have you made sure that the second document is valid xml? The best way to do this would be to load the document in internet explorer. You will get an error if the document is not valid. What exception message are you getting when the code crashes? This can usually lead you to the source of the problem. Regards Mark Smithson

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            you are right again - the XML was not valid thanks and regards

            1 Reply Last reply
            0
            • M Mark Smithson

              Have you made sure that the second document is valid xml? The best way to do this would be to load the document in internet explorer. You will get an error if the document is not valid. What exception message are you getting when the code crashes? This can usually lead you to the source of the problem. Regards Mark Smithson

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              :-Oyou are right again - the XML was not valid thanks and regards:-O

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups