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

working with System.Xml.XmlDocument.


Hello,
I'm calling a webmethod from a webservice written in java.
I need to pass an xml file as parameter to the webmethod.
I therefore use System.Xml.XmlDocument to load the xml file.
The call works when i construct a string representation of the content of
the xml and then, use the "loadxml" method to of Xml.XmlDocument .

But it fails when i load the file directly into and System.Xml.XmlDocument
objet by using the load method.

could it be that a windows specifiix formating is added to the xml content
and if yes how can i fix it?

Many thanks in advance
JJ
Feb 6 '06 #1
14 2700
jens Jensen wrote:
I'm calling a webmethod from a webservice written in java.
I need to pass an xml file as parameter to the webmethod.
I therefore use System.Xml.XmlDocument to load the xml file.

The call works when i construct a string representation of the content of
the xml and then, use the "loadxml" method to of Xml.XmlDocument .

But it fails when i load the file directly into and System.Xml.XmlDocument
objet by using the load method.

could it be that a windows specifiix formating is added to the xml content
and if yes how can i fix it?


That's unlikely, although as you haven't said what saved the file, it's
possible.

It would really help if you'd say in what way it fails... can you
provide a short but complete program (and sample file) which
demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for more
information.

Jon

Feb 6 '06 #2
> It would really help if you'd say in what way it fails... can you
provide a short but complete program (and sample file) which
demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for more
information.

Jon


Method that works:

ProxyClass GetMess = new ProxyClass();

System.Xml.XmlDocument xmlIn = new XmlDocument();

System.Xml.XmlDocument xmlOut = new XmlDocument();

String str;

str = "build the string";(packing the xml into a string")

xmlIn.LoadXml(str);

xmlOut = GetMess.processMessage(xmlIn);



******************************************

Method that dont work:( error: object not set to the instance of an object
on :xmlOut = GetMess.processMessage(xmlIn);)

ProxyClass GetMess = new ProxyClass();

System.Xml.XmlDocument xmlIn = new XmlDocument();

System.Xml.XmlDocument xmlOut = new XmlDocument();

XmlTextReader reader = new XmlTextReader("xml file");

xmlIn.Load(reader);

xmlOut = GetMess.processMessage(xmlIn); (throughs exception described
earlier here)

Many thanks

JJ




Feb 6 '06 #3


jens Jensen wrote:

I'm calling a webmethod from a webservice written in java.
I need to pass an xml file as parameter to the webmethod.
I therefore use System.Xml.XmlDocument to load the xml file.
The call works when i construct a string representation of the content of
the xml and then, use the "loadxml" method to of Xml.XmlDocument .

But it fails when i load the file directly into and System.Xml.XmlDocument
objet by using the load method.


What exactly fails, loading the XML, calling the web service with the
XML as a parameter? What error message do you get? Does the error happen
in your .NET client calling the Java web service and/or in the Java web
service?


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Feb 6 '06 #4
jens Jensen wrote:
Method that works:


<snip>

Please see http://www.pobox.com/~skeet/csharp/incomplete.html

Jon

Feb 6 '06 #5
Hi Jens;

In both critical sections the important code is missing; an example xml /
path. However - some thoughts:

- Do you get the same thing if you .Load(myFilePath) rather than
..Load(reader)?
- Are you absolutely sure that your file path is correct and that the file
contains data? (for instance, does .ReadOuterXml() return what you expect)
- If "yes" to the above, is the documents .OuterXml what you expect?
- And if "yes" to the above, are you sure it isn't the Java?

I guess the real question is: when is the xml first not what you expect?
Because that is where you need to look...

Marc
Feb 6 '06 #6
> .Load(reader)?
- Are you absolutely sure that your file path is correct and that the file
contains data? (for instance, does .ReadOuterXml() return what you expect)
- If "yes" to the above, is the documents .OuterXml what you expect?
- And if "yes" to the above, are you sure it isn't the Java?

I guess the real question is: when is the xml first not what you expect?
Because that is where you need to look...

Marc

Thanks Mark,

For security reasons, i cant reveal here the content of the xml file . But
as i said earlier, the fist block ends the call the webserivce as expected.

I will now investigate your question and get back here.
Many thanks
JJ
Feb 6 '06 #7
- Do you get the same thing if you .Load(myFilePath) rather than
..Load(reader)?

yes, i checked this by doing :xmlIn.Save("C:\\test.xml") and i get the same
result as the original file.
- Are you absolutely sure that your file path is correct and that the file
contains data? (for instance, does .ReadOuterXml() return what you expect)
yes

- If "yes" to the above, is the documents .OuterXml what you expect?

yes just checked it
- And if "yes" to the above, are you sure it isn't the Java?
well when i construct the string as it should be in the xml file, then the
call return what i expect.
The string loaded into the xml file is exactly the same as what i see when i
open the xml fil in notepad.
Sorry againg that i cant provide the xml file. I hope this info is enough
for diagnostic.

Feb 6 '06 #8
I appreciate that, and I don't think we need your *actual* xml; what would
help, though, is XML that can genuinely be used (either as a string or as a
file on the HDD) to illustrate the problem. It comes down to the point (on
Jon's page about complete examples) about posting enough information to
reproduce the problem without posting unnecessary stuff.

Myself, I'm a great believer in "<Xml/>"; this wee-beastie has debugged more
code than I care to admit. So: does this problem exhibit itself with such a
trivial example (and a web-service that at least doesn't barf at such). If
it *does* still display the same issue, then the problem is in loading, and
the people on this forum can probably fix it in about 5 minutes *if* you
post an actual example that shows the problem... because the following
really, really won't work (or even compile) and doesn't help anyone to help
you:

str = "build the string";(packing the xml into a string")
xmlIn.LoadXml(str);

If a trivial piece of xml does *not* show the problem, the the problem is
likely either the xml itself or the web-service reading it (although if it
was the xml I wouldn't expect it to get much past loading the xml without
throwing an exception).

Marc
Feb 6 '06 #9
Try the following:

* use .LoadXml with the string that works
* use .Save to write the file to the HDD

Now compare the 2 files (i.e. the one you think is correct and the one that
is written by XmlDocument) - this is easier if your diffing tool can ignore
xml white-space...

I suspect that the file version may be incorrect; as an example:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<xml>?</xml>"); // the character in the middle here is dagger
(0134 decimal)
doc.Save("d:\\test.xml");

If I now look at the xml it is very different:
<xml>â? </xml>
I'm not even going to try to describe those 2 chars ;-p
Could something like this explain the problem? Particularly if you are using
strings to write the "xml" file?

Marc
Feb 6 '06 #10
Note that my "dagger" got stripped; if you see ? just replace it by holding
[Alt] and press [0], [1], [3], [4] on the numeric keypad. The output chars
also got changed.

Ahh the joys of encoding ;-p

Marc
Feb 6 '06 #11
Ok
Many thanks. I will do what you said.
JJ
Feb 6 '06 #12

"Marc Gravell" <mg******@rm.com> skrev i en meddelelse
news:%2***************@tk2msftngp13.phx.gbl...
Note that my "dagger" got stripped; if you see ? just replace it by
holding [Alt] and press [0], [1], [3], [4] on the numeric keypad. The
output chars also got changed.

Ahh the joys of encoding ;-p

Marc

Ultraedit shows some differences between the two files. There appear to be
only white spaces.
The non working version contains somes spaces.

Should white spaces cause this behaviour?

I should probably asking this question to the java developers... But what do
you think?
Feb 6 '06 #13
Nope; that shouldn't cause any problems. 'twas just a hunch.

Very curious. About this time I would be installing ehtereal... I'd be
looking to see:
* Does it error without talking to the web-service
* If the web-service responds, does it return (valid) data or an error
etc...

Other than that it could be very hard to diagnose in such an abstract way
;-(

Marc
Feb 6 '06 #14
> Very curious. About this time I would be installing ehtereal... I'd be
looking to see:
* Does it error without talking to the web-service
* If the web-service responds, does it return (valid) data or an error
etc...

Other than that it could be very hard to diagnose in such an abstract way
;-(

Marc


Good questions, i will investigate.
Feb 6 '06 #15

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

Similar topics

4
by: Jay Douglas | last post by:
Hello all, I have a basic XML file of which I set the Build Action to "Embedded Resource" The XML file is simple: <root> <item> <name>Test Name</name> <description>Test...
1
by: Glenn Venzke | last post by:
I'm trying to invoke the "selectsinglenode" method on an XmlDocument object, but it doesn't seem able to find the node I want. I'm able to access the document root but when I try to parse an...
1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
0
by: Luis Esteban Valencia | last post by:
Hello I have this error when I submit the page with the following code. I had never see this kind of errors. Thanks private void btnsubmit_Click(object sender, System.EventArgs e) { ...
0
by: Gustaf | last post by:
I'd like to see if someone found a natural explanation to this. I have this method for transforming docs: /** * Transforms an XmlDocument object with an XSL file, and returns * another...
2
by: John Smith | last post by:
I'm writing webervice client using .Net 2.0. I have this class: public class MyWebService : SoapHttpClientProtocol { public XmlDocument validate(string url, XmlDocument xmlDocument) {...
4
by: John Smith | last post by:
How can I allow someone to cast my C# class into System.String? Is it possible in C#? In C++ I used "operator" keyword to mark C++ member function.
1
by: kowshikj | last post by:
In a ASP.NET 1.1 application, we get this exception at xmlDoc.Load() when loading an XmlDocument. This does not seem to happen every time though. The xml file itself is only 10 KB and we don't use...
5
by: qatarya3sal | last post by:
Imports System.XML Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ...
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?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.