473,395 Members | 1,738 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.

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 3851
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ian Williamson | last post by:
Greetings, I have seen this question posted a few times, but the answers have not helped me. I have used the program xsd.exe to generate several c# classes from a client provided xsd...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
3
by: Siu | last post by:
Hi, I've loaded an XmlDocument from a file XML: this file has many similar XmlNode and it is difficult to select them by using SelectSingleNode of the object XmlDocument. I've this question: is...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
0
by: jens Jensen | last post by:
Hello, I have built a client of a websevrice. I call a webmethod that takes an Xmldocument object and returns an Xmldocument object. When i add a refernce to this webservice on the client, then...
4
by: jens Jensen | last post by:
Hello, I have built a client of a websevrice. I call a webmethod that takes an Xmldocument object and returns an Xmldocument object. When i add a refernce to this webservice on the client, then...
3
by: Earl | last post by:
In VB.Net, the following declaration builds and executes with no exceptions: Dim XMLDoc As New XmlDocument Dim Node As XmlNode But in C#, the following (equivalent?!) returns the build error...
1
by: Andrus | last post by:
How to remove whole Xmlnode so that outer tags are also removed ? To reproduce, run the code. Observed result: <Query> <DataSourceName>DS1</DataSourceName> <QueryParameters>...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.