working with System.Xml.XmlDocument.

J

jens Jensen

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
 
J

Jon Skeet [C# MVP]

jens said:
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
 
J

jens Jensen

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
 
M

Martin Honnen

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?
 
M

Marc Gravell

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
 
J

jens Jensen

.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
 
M

Marc Gravell

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
 
J

jens Jensen

- 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.
 
M

Marc Gravell

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
 
M

Marc Gravell

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
 
J

jens Jensen

Marc Gravell said:
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?
 
M

Marc Gravell

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
 
J

jens Jensen

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top