473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Cannot implicitly convert type 'object' to 'System.Xml.XmlDocument' Error

compiling the code below i get the error:-

Cannot implicitly convert type 'object'to 'System.Xml.XmlDocument'

I'm getting the error on this line:-

myXml.Document = getXML("http://www.crn.com.au/rss.aspx?SCID=9");

Any ideas?

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

myXml.Document = getXML("http://www.crn.com.au/rss.aspx?SCID=9");
}

object getXML(string sourceFile)
{
System.Net.WebRequest myRequest =
System.Net.WebRequest.Create(sourceFile);
System.Net.WebResponse myResponse = myRequest.GetResponse();
System.Xml.XmlTextReader myReader = new
System.Xml.XmlTextReader(myResponse.GetResponseStr eam());
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(myReader);
getXML = doc;


myResponse.Close();
myReader.Close();
}
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
3 6025
Patrick Olurotimi Ige <na********@hotmail.com> wrote in
news:ug**************@TK2MSFTNGP14.phx.gbl:
compiling the code below i get the error:-

Cannot implicitly convert type 'object'to
'System.Xml.XmlDocument'

I'm getting the error on this line:-

myXml.Document =
getXML("http://www.crn.com.au/rss.aspx?SCID=9");

Any ideas?

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

myXml.Document =
getXML("http://www.crn.com.au/rss.aspx?SCID=9");
}

object getXML(string sourceFile)
{
System.Net.WebRequest myRequest =
System.Net.WebRequest.Create(sourceFile);
System.Net.WebResponse myResponse =
myRequest.GetResponse(); System.Xml.XmlTextReader
myReader = new
System.Xml.XmlTextReader(myResponse.GetResponseStr eam());
System.Xml.XmlDocument doc = new
System.Xml.XmlDocument(); doc.Load(myReader);
getXML = doc;
myResponse.Close();
myReader.Close();
}


Patrick,

There are two modifications that need to be made.

1. In the getXML method, the return value is never set. The line of
code "getXML = doc;" will not compile. To return the XmlDocument,
change that line of code to "return doc;" and move it to the end of
the method.

2. The error message you are receiving is correct. You must perform
an explicit cast:

myXml.Document =
(XmlDocument) getXML("http://www.crn.com.au/rss.aspx?SCID=9");

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 19 '05 #2
It actually looks like you have a couple of problems:

1.) replace object getXML(string sourceFile) with
XmlDocument getXML(string sourceFile)
OR
repace myXml.Document = getXML("http://www.crn.com.au/rss.aspx?SCID=9");
with
myXml.Document =
(XmlDocument)getXML("http://www.crn.com.au/rss.aspx?SCID=9");

2.) replace getXML = doc; with
return doc; [and move it to the end of the method after you close
the Response and Reader objects]
HTH
----------------
Dave Fancher
http://davefancher.blogspot.com
Nov 19 '05 #3
Thx Dave and Chris for the quick response!
Need some C# brush up

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
1
by: David C. allen | last post by:
I have created a simple Client-side SOAP Extension for a webclass that I have. When I apply the extension attribute to the the calling function in the proxy class I get an error 'Value cannot be...
1
by: Svyatoslav | last post by:
Hi, I have a problem with XmlNodes and my stack. It looks something like this: //declarations XmlNode node, new_node; Stack MyStack = new Stack(); //code MyStack.Push(node);
22
by: Christoph Boget | last post by:
I am getting an error (a few among many) for the following lines of code: retval.BrokerName = (( curRow == System.DBNull.Value ) ? SqlString.Null : (string)curRow ); retval.BrokerGroupId = ((...
6
by: juli | last post by:
I declared: public delegate void PaintEventHandler(object objSender,PaintEventArgs pea); and this.Paint+=new PaintEventHandler(MyPaintHandler); and the: static void MyPaintHandler(object...
2
by: Patrick Olurotimi Ige | last post by:
When i convert:- this code from VB to C# Why do i get error "Cannot implicitly convert type 'object' to 'bool' VB --- If cmdcommand.Parameters("ReturnValue").Value = 1 Then lblStatus.Text =...
9
by: Andy Sutorius | last post by:
Hi, I am receiving the error when compiling the project, "cannot implicitly convert type object to string". The error points to this line of code and underlines the dtrRecipient:...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
7
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.