open two XmlDocuments at same time
-
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);
-
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);
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
-
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
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);
-
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);
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
-
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
-
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