473,748 Members | 2,469 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

compiling the code below i get the error:-

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

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(objec t sender, System.EventArg s 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.WebR equest myRequest =
System.Net.WebR equest.Create(s ourceFile);
System.Net.WebR esponse myResponse = myRequest.GetRe sponse();
System.Xml.XmlT extReader myReader = new
System.Xml.XmlT extReader(myRes ponse.GetRespon seStream());
System.Xml.XmlD ocument doc = new System.Xml.XmlD ocument();
doc.Load(myRead er);
getXML = doc;


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

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

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(objec t sender, System.EventArg s 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.WebR equest myRequest =
System.Net.WebR equest.Create(s ourceFile);
System.Net.WebR esponse myResponse =
myRequest.GetRe sponse(); System.Xml.XmlT extReader
myReader = new
System.Xml.XmlT extReader(myRes ponse.GetRespon seStream());
System.Xml.XmlD ocument doc = new
System.Xml.XmlD ocument(); doc.Load(myRead er);
getXML = doc;
myResponse.Clos e();
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)ge tXML("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
14971
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 = ddDes.SelectedItem.ToString(); xmlDocument.Save("abc.xml"); However, I get the foll. error: Cannot implicitly convert type 'System.Xml.XmlNode' to 'System.Xml.XmlAttribute'
1
5727
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 null'. When the extension attribute is not applied it runs fine. The wierd thing is that it does not appear to be an error within the SOAP extension because I break-pointed it and when the proxy function gets called the SOAP extension runs fine....
1
4705
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
27892
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 = (( curRow == System.DBNull.Value ) ? SqlInt32.Null : (int)curRow ); The errors are (in turn):
6
14378
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 objSender,PaintEventArgs pea) { }
2
6736
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 = "Username already exists!" Else lblStatus.Text = "Success!"
9
10529
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: objMailMessage.To = dtrRecipient; I'm not sure why I am getting this error. Below is the complete code I am working with.
2
13590
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) { this.Url = url;
7
16706
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 returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T GetValue<T(string objName) { T results;
0
8995
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6799
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.