473,226 Members | 1,515 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,226 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 4857
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.