472,993 Members | 2,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 3827
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.