471,082 Members | 748 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

XMLNode - XMLDocument types question

I have a web service method that returns an XMLDocument. The signature is:
public XmlDocument GetPOs()

The following client code calls this method but it accepts an XMLNode
instead of an XMLDocument and my first question is why does this work?
XmlNode neNode;
neNode = myHFCService.GetPOs();
DataSet myds = new DataSet();
byte[] buf =
System.Text.ASCIIEncoding.ASCII.GetBytes(neNode.Ou terXml);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
myds.ReadXml(ms);
gvOrders.DataSource = myds.Tables[0];
Secondly, why does the following client code get a type mismatch?

XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc = myHFCService.GetPOs();

The service is returning a type of XMLDocument but it comes back as XMLNode.
Those are different types.

Thanks,
Gary
Mar 10 '07 #1
5 3699
GaryDean wrote:
I have a web service method that returns an XMLDocument. The signature is:
public XmlDocument GetPOs()

The following client code calls this method but it accepts an XMLNode
instead of an XMLDocument and my first question is why does this work?
XmlNode neNode;
neNode = myHFCService.GetPOs();
DataSet myds = new DataSet();
byte[] buf =
System.Text.ASCIIEncoding.ASCII.GetBytes(neNode.Ou terXml);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buf);
myds.ReadXml(ms);
gvOrders.DataSource = myds.Tables[0];
Secondly, why does the following client code get a type mismatch?

XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc = myHFCService.GetPOs();
XmlNode is the base class for all those specialized classes like
XmlElement or XmlDocument. When you get a piece of XML markup in the
SOAP response I think it is difficult to distinguish whether e.g
<element>content</element>
is the result of serializing an XmlDocument instance or an XmlElement
instance so you get an XmlNode as the common subclass.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Mar 11 '07 #2
Hi Gary,
Thanks for Martin's reply.

Yes, as Martin said.
XmlDocument is derived from XmlNode. When XmlDocument objects are passed as
parameters to Web Service methods, or are returned from Web Service
methods, they are marshaled as XmlNode objects. This behavior is by design.

We suggest you may use XmlDocument API to load data from XMLNode.
For example:

XmlDocument myXMLDoc = new XmlDocument();
myXMLDoc.LoadXml(myHFCService.GetPOs().OuterXml);

For more information, you can reference the following KB.
http://support.microsoft.com/kb/330600/en-us

Please feel free to let me know if there is anything unclear. I'm glad to
assist you.

Hope this helps.
Sincerely,
Wen Yuan

Mar 12 '07 #3
Hi Gary,

I just want to check whether your issue has been resolved.
Please feel free to update here if it still persists. I'm glad to assist
you.

Have a great day,
Sincerely,
Wen Yuan

Mar 14 '07 #4
Wen Yuan,
sorry for so long to get back to you but I got busy on something else...

Yes your response and the associate docs explain this behavior.

thanks very much for the help!

--
Regards,
Gary Blakely
""WenYuan Wang"" <v-******@online.microsoft.comwrote in message
news:5l**************@TK2MSFTNGHUB02.phx.gbl...
Hi Gary,

I just want to check whether your issue has been resolved.
Please feel free to update here if it still persists. I'm glad to assist
you.

Have a great day,
Sincerely,
Wen Yuan

Mar 30 '07 #5
Hi Gary,

Thanks for your response.
I'm glad to assist you.:)

Have a great day,
Sincerely,
Wen Yuan

Apr 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Ian Williamson | last post: by
3 posts views Thread by Mahesh Devjibhai Dhola | last post: by
3 posts views Thread by Siu | last post: by
5 posts views Thread by Paul | last post: by
5 posts views Thread by Mahesh Devjibhai Dhola | last post: by
reply views Thread by jens Jensen | last post: by
4 posts views Thread by jens Jensen | last post: by
3 posts views Thread by Earl | last post: by
1 post views Thread by Andrus | last post: by

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.