471,627 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 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 2623
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jay Douglas | last post: by
1 post views Thread by Glenn Venzke | last post: by
1 post views Thread by Martin Honnen | last post: by
reply views Thread by Gustaf | last post: by
4 posts views Thread by John Smith | last post: by
1 post views Thread by kowshikj | last post: by
5 posts views Thread by qatarya3sal | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | 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.