473,402 Members | 2,055 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,402 software developers and data experts.

Error using XMLTextReader to read XMLDocument

I have a Web Service in which I am trying to pass an XMLDocument as a
parameter to one of the methods. I would like to use the XMLTextReader to
read the XML but I am getting the following error:

Value of type System.xml.xmldocument cannot be converted to
System.IO.textreader.

I would think this is possible to do.

Code snippet is below:

-------------------------------------------------------
Public Function ChangeAddress(ByVal xml As
XmlDocument) As Boolean

Try

Dim xtr As New XmlTextReader(xml)

-------------------------------------------------------

Any and all help is greatfully appreciated.

--
Thanks,

Scott
Nov 12 '05 #1
7 4868
Hi Scott

You could do this (code follows), but I'm not sure why you would want to...?

Essentially, the XmlDocument, (xml in your method) is an in memory tree of
your XML data - the code below serializes the tree to a string, then reads it
in again...it's kind of wasteful. If you want to access content of the
document, then use methods like SelectNodes, GetElementsByTagName, and so on
to read through the data in memory...

Nigel
Code:
Public Function ChangeAddress(ByVal xml As XmlDocument)
Dim sr As New IO.StringReader(xml.OuterXml)
Dim t As New Xml.XmlTextReader(sr)
While t.Read
MessageBox.Show(t.Name)
End While
End Function

"SQLScott" wrote:
I have a Web Service in which I am trying to pass an XMLDocument as a
parameter to one of the methods. I would like to use the XMLTextReader to
read the XML but I am getting the following error:

Value of type System.xml.xmldocument cannot be converted to
System.IO.textreader.

I would think this is possible to do.

Code snippet is below:

-------------------------------------------------------
Public Function ChangeAddress(ByVal xml As
XmlDocument) As Boolean

Try

Dim xtr As New XmlTextReader(xml)

-------------------------------------------------------

Any and all help is greatfully appreciated.

--
Thanks,

Scott

Nov 12 '05 #2
Thanks Nigel, I appreciate the response.

You state "why would you want to?". Is there a better of doing what I am
tryign to accomplish? Should I not be passing an XMLDocument?

Scott

"Nigel Armstrong" wrote:
Hi Scott

You could do this (code follows), but I'm not sure why you would want to...?

Essentially, the XmlDocument, (xml in your method) is an in memory tree of
your XML data - the code below serializes the tree to a string, then reads it
in again...it's kind of wasteful. If you want to access content of the
document, then use methods like SelectNodes, GetElementsByTagName, and so on
to read through the data in memory...

Nigel
Code:
Public Function ChangeAddress(ByVal xml As XmlDocument)
Dim sr As New IO.StringReader(xml.OuterXml)
Dim t As New Xml.XmlTextReader(sr)
While t.Read
MessageBox.Show(t.Name)
End While
End Function

"SQLScott" wrote:
I have a Web Service in which I am trying to pass an XMLDocument as a
parameter to one of the methods. I would like to use the XMLTextReader to
read the XML but I am getting the following error:

Value of type System.xml.xmldocument cannot be converted to
System.IO.textreader.

I would think this is possible to do.

Code snippet is below:

-------------------------------------------------------
Public Function ChangeAddress(ByVal xml As
XmlDocument) As Boolean

Try

Dim xtr As New XmlTextReader(xml)

-------------------------------------------------------

Any and all help is greatfully appreciated.

--
Thanks,

Scott

Nov 12 '05 #3
Hi Scott

I don't have a problem with you passing an XmlDocument via a Web service!
It's just that with your XmlDocument parameter on your Web service method,
you already have a programmatic interface to your XML data - there's no need
to reparse it with the XmlTextReader...so as I mentioned in my previous post,
you can use GetElementsByTagName(), SelectNodes() and so on to get access to
the data, you don't need to reparse.

Nigel Armstrong

"SQLScott" wrote:
Thanks Nigel, I appreciate the response.

You state "why would you want to?". Is there a better of doing what I am
tryign to accomplish? Should I not be passing an XMLDocument?

Scott

"Nigel Armstrong" wrote:
Hi Scott

You could do this (code follows), but I'm not sure why you would want to...?

Essentially, the XmlDocument, (xml in your method) is an in memory tree of
your XML data - the code below serializes the tree to a string, then reads it
in again...it's kind of wasteful. If you want to access content of the
document, then use methods like SelectNodes, GetElementsByTagName, and so on
to read through the data in memory...

Nigel
Code:
Public Function ChangeAddress(ByVal xml As XmlDocument)
Dim sr As New IO.StringReader(xml.OuterXml)
Dim t As New Xml.XmlTextReader(sr)
While t.Read
MessageBox.Show(t.Name)
End While
End Function

"SQLScott" wrote:
I have a Web Service in which I am trying to pass an XMLDocument as a
parameter to one of the methods. I would like to use the XMLTextReader to
read the XML but I am getting the following error:

Value of type System.xml.xmldocument cannot be converted to
System.IO.textreader.

I would think this is possible to do.

Code snippet is below:

-------------------------------------------------------
Public Function ChangeAddress(ByVal xml As
XmlDocument) As Boolean

Try

Dim xtr As New XmlTextReader(xml)

-------------------------------------------------------

Any and all help is greatfully appreciated.

--
Thanks,

Scott

Nov 12 '05 #4
Ah, ok, i'm with you now. It makes sense now that I have gone back to
re-read your original answer. Sorry for the confusion.

Scott

"Nigel Armstrong" wrote:
Hi Scott

I don't have a problem with you passing an XmlDocument via a Web service!
It's just that with your XmlDocument parameter on your Web service method,
you already have a programmatic interface to your XML data - there's no need
to reparse it with the XmlTextReader...so as I mentioned in my previous post,
you can use GetElementsByTagName(), SelectNodes() and so on to get access to
the data, you don't need to reparse.

Nigel Armstrong

"SQLScott" wrote:
Thanks Nigel, I appreciate the response.

You state "why would you want to?". Is there a better of doing what I am
tryign to accomplish? Should I not be passing an XMLDocument?

Scott

"Nigel Armstrong" wrote:
Hi Scott

You could do this (code follows), but I'm not sure why you would want to...?

Essentially, the XmlDocument, (xml in your method) is an in memory tree of
your XML data - the code below serializes the tree to a string, then reads it
in again...it's kind of wasteful. If you want to access content of the
document, then use methods like SelectNodes, GetElementsByTagName, and so on
to read through the data in memory...

Nigel
Code:
Public Function ChangeAddress(ByVal xml As XmlDocument)
Dim sr As New IO.StringReader(xml.OuterXml)
Dim t As New Xml.XmlTextReader(sr)
While t.Read
MessageBox.Show(t.Name)
End While
End Function

"SQLScott" wrote:

> I have a Web Service in which I am trying to pass an XMLDocument as a
> parameter to one of the methods. I would like to use the XMLTextReader to
> read the XML but I am getting the following error:
>
> Value of type System.xml.xmldocument cannot be converted to
> System.IO.textreader.
>
> I would think this is possible to do.
>
> Code snippet is below:
>
> -------------------------------------------------------
> Public Function ChangeAddress(ByVal xml As
> XmlDocument) As Boolean
>
> Try
>
> Dim xtr As New XmlTextReader(xml)
>
> -------------------------------------------------------
>
> Any and all help is greatfully appreciated.
>
> --
> Thanks,
>
> Scott

Nov 12 '05 #5
Nigel, quick question. When I write the code to call the method adn pass it
an XMLDocument, the intellisense displays the parameter as:

system.xml.xmlnode

IN other words, bReturn = ws.CallMethod(xml as system.xml.xmlnode)

Even though the parameter on the method is ByVal xml as XMLDocument.

I am at a loss. Any ideas why? Many thanks for your help on this.

"Nigel Armstrong" wrote:
Hi Scott

I don't have a problem with you passing an XmlDocument via a Web service!
It's just that with your XmlDocument parameter on your Web service method,
you already have a programmatic interface to your XML data - there's no need
to reparse it with the XmlTextReader...so as I mentioned in my previous post,
you can use GetElementsByTagName(), SelectNodes() and so on to get access to
the data, you don't need to reparse.

Nigel Armstrong

"SQLScott" wrote:
Thanks Nigel, I appreciate the response.

You state "why would you want to?". Is there a better of doing what I am
tryign to accomplish? Should I not be passing an XMLDocument?

Scott

"Nigel Armstrong" wrote:
Hi Scott

You could do this (code follows), but I'm not sure why you would want to...?

Essentially, the XmlDocument, (xml in your method) is an in memory tree of
your XML data - the code below serializes the tree to a string, then reads it
in again...it's kind of wasteful. If you want to access content of the
document, then use methods like SelectNodes, GetElementsByTagName, and so on
to read through the data in memory...

Nigel
Code:
Public Function ChangeAddress(ByVal xml As XmlDocument)
Dim sr As New IO.StringReader(xml.OuterXml)
Dim t As New Xml.XmlTextReader(sr)
While t.Read
MessageBox.Show(t.Name)
End While
End Function

"SQLScott" wrote:

> I have a Web Service in which I am trying to pass an XMLDocument as a
> parameter to one of the methods. I would like to use the XMLTextReader to
> read the XML but I am getting the following error:
>
> Value of type System.xml.xmldocument cannot be converted to
> System.IO.textreader.
>
> I would think this is possible to do.
>
> Code snippet is below:
>
> -------------------------------------------------------
> Public Function ChangeAddress(ByVal xml As
> XmlDocument) As Boolean
>
> Try
>
> Dim xtr As New XmlTextReader(xml)
>
> -------------------------------------------------------
>
> Any and all help is greatfully appreciated.
>
> --
> Thanks,
>
> Scott

Nov 12 '05 #6
Scott

In practice it won't matter! The node that you get is actually a
System.Xml.XmlElement - this code illustrates:

Dim s As New localhost.XmlService
Dim n As System.Xml.XmlNode = s.HelloWorld
MessageBox.Show(n.NodeType & " " & n.OuterXml)

What do you need to do with the returned data??

HTH

Nigel

"SQLScott" wrote:
Nigel, quick question. When I write the code to call the method adn pass it
an XMLDocument, the intellisense displays the parameter as:

system.xml.xmlnode

IN other words, bReturn = ws.CallMethod(xml as system.xml.xmlnode)

Even though the parameter on the method is ByVal xml as XMLDocument.

I am at a loss. Any ideas why? Many thanks for your help on this.

"Nigel Armstrong" wrote:
Hi Scott

I don't have a problem with you passing an XmlDocument via a Web service!
It's just that with your XmlDocument parameter on your Web service method,
you already have a programmatic interface to your XML data - there's no need
to reparse it with the XmlTextReader...so as I mentioned in my previous post,
you can use GetElementsByTagName(), SelectNodes() and so on to get access to
the data, you don't need to reparse.

Nigel Armstrong

"SQLScott" wrote:
Thanks Nigel, I appreciate the response.

You state "why would you want to?". Is there a better of doing what I am
tryign to accomplish? Should I not be passing an XMLDocument?

Scott

"Nigel Armstrong" wrote:

> Hi Scott
>
> You could do this (code follows), but I'm not sure why you would want to...?
>
> Essentially, the XmlDocument, (xml in your method) is an in memory tree of
> your XML data - the code below serializes the tree to a string, then reads it
> in again...it's kind of wasteful. If you want to access content of the
> document, then use methods like SelectNodes, GetElementsByTagName, and so on
> to read through the data in memory...
>
> Nigel
> Code:
> Public Function ChangeAddress(ByVal xml As XmlDocument)
> Dim sr As New IO.StringReader(xml.OuterXml)
> Dim t As New Xml.XmlTextReader(sr)
> While t.Read
> MessageBox.Show(t.Name)
> End While
> End Function
>
> "SQLScott" wrote:
>
> > I have a Web Service in which I am trying to pass an XMLDocument as a
> > parameter to one of the methods. I would like to use the XMLTextReader to
> > read the XML but I am getting the following error:
> >
> > Value of type System.xml.xmldocument cannot be converted to
> > System.IO.textreader.
> >
> > I would think this is possible to do.
> >
> > Code snippet is below:
> >
> > -------------------------------------------------------
> > Public Function ChangeAddress(ByVal xml As
> > XmlDocument) As Boolean
> >
> > Try
> >
> > Dim xtr As New XmlTextReader(xml)
> >
> > -------------------------------------------------------
> >
> > Any and all help is greatfully appreciated.
> >
> > --
> > Thanks,
> >
> > Scott

Nov 12 '05 #7
That is completely correct.

If you are working with Web services, you need to think about the contract
(WSDL) that is the basis for clients consuming your Web service. ASP.NET
makes working with WSDL both easy and makes this hard by automatically
generating WSDL for you based on XML Serialization and various attributes in
your code. Easy because often you don't have to do anything to make the
right (or a reasonable) thing happen. Hard because you still have to think
about the WSDL that ASP.NET is generating, since that is all the client
sees.

It is important to note that Web services have *nothing* to do with objects
and object-orientation. Web services pass XML data, not objects, not types.
Both System.Xml.XmlNode and System.Xml.XmlDocument serialize down in your
Web service message to an arbritrary, unconstrained XML element, represented
in the WSDL as the XSD type <xs:any/>. Later, when you add a Web reference
to a project, Visual Studio takes the WSDL for the Web service and creates
proxy classes for the types represented in the WSDL. In other words, the
proxy classes map XML data into classes. When a proxy classes are generated
for a WSDL document, <xs:any/> maps to XmlNode.

Consider your Web service from the perspective of clients that consume your
Web service using different platforms, languages or vendors, say a J2EE
client on a Sun or IBM system. They can consume an XML element (<xs:any/>)
in your SOAP message, but that don't know anything about .NET Framework
classes like XmlNode or XmlDocument. So you have to see beyond the
ASP.NET-ism of thinking you are passing an XmlDocument on a Web service
endpoint: you are passing what the WSDL says you are passing, and that's XML
data.

Cheers,
Stuart Celarier, Fern Creek
Nov 12 '05 #8

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

Similar topics

0
by: Jason | last post by:
I have an XML web control on a usercontrol. The only purpose for this usercontrol is to get XML data from a URL and display it in the xml web control with the help of XSL. I can get this to...
4
by: sunil | last post by:
I am creating a XML document which opens fine in IE. Implies MSXML thinks it is a well formed document. But when I try to load this document in VB.net using the following code Dim doc As New...
0
by: SqlJunkies User | last post by:
I have pretty same problem with XmlDocument.Load(). It seems to appear after KB834623 hotfix installed. Here is the information to reproduce error: Technical info: • Windows XP Professional SP1...
1
by: Sammy | last post by:
Can anyone please explain me the cause and resolution of this error. TIA Sammy Server Error in '/' Application. The device is not ready. Description: An unhandled exception occurred during...
5
by: Patrick | last post by:
I understand it is built in behaviour that if an ASP.NET's web.config is set to: <customErrors mode="RemoteOnly" /> then I only get a detailed error message on screen when the ASP.NET...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
4
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
0
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku...
1
by: santoshsri | last post by:
Hi All, My C# web application calls a webservice to process a report. It sends XMLs as parameter and in response gets an XML node which stores Binay datatype bin.base64. It makes an instance of...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.