-
March 6th, 2012, 04:31 PM
#1
XMLReader not working
Hello!
I'm playing around trying to read XML-files from the Internet to parse, but I can't get it to work at all. Some code:
try {
HttpWebRequest^ req = dynamic_cast<HttpWebRequest^> (WebRequest::Create( "http://www.xmlfiles.com/examples/note.xml" ));
HttpWebResponse^ res = dynamic_cast<HttpWebResponse^> (req->GetResponse());
Stream^ stm = res->GetResponseStream();
XmlTextReader^ reader;
try {reader = dynamic_cast<XmlTextReader^>(XmlTextReader::Create(stm)); }
catch (...){Console::WriteLine("b");}
while (reader->Read()){
switch (reader->NodeType){
default:
Console::WriteLine("a");
// Console::WriteLine(String::Concat( reader->NodeType.ToString(), ": ","<", reader->Name, ">",reader->Value));
break;
}
}
}
catch (Exception^ e){
Console::WriteLine(e->StackTrace);
Console::WriteLine(e->Message);
}
All I get is an error: "Object reference not set to an instance of an object. The stacktrace points at the Read()-operation.
Anyone know about how to solve this?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|