working with System.Xml.XmlDocument.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jens Jensen

    #1

    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.XmlD ocument 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.XmlD ocument
    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


  • Jon Skeet [C# MVP]

    #2
    Re: working with System.Xml.XmlD ocument.

    jens Jensen wrote:[color=blue]
    > 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.XmlD ocument 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.XmlD ocument
    > 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?[/color]

    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

    Comment

    • jens Jensen

      #3
      Re: working with System.Xml.XmlD ocument.

      > It would really help if you'd say in what way it fails... can you[color=blue]
      > 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
      >[/color]



      Method that works:



      ProxyClass GetMess = new ProxyClass();

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

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



      String str;

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

      xmlIn.LoadXml(s tr);

      xmlOut = GetMess.process Message(xmlIn);







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



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





      ProxyClass GetMess = new ProxyClass();

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

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



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

      xmlIn.Load(read er);



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



      Many thanks

      JJ










      Comment

      • Martin Honnen

        #4
        Re: working with System.Xml.XmlD ocument.



        jens Jensen wrote:

        [color=blue]
        > 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.XmlD ocument 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.XmlD ocument
        > objet by using the load method.[/color]

        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/

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: working with System.Xml.XmlD ocument.

          jens Jensen wrote:[color=blue]
          > Method that works:[/color]

          <snip>

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

          Jon

          Comment

          • Marc Gravell

            #6
            Re: working with System.Xml.XmlD ocument.

            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(myFilePat h) 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


            Comment

            • jens Jensen

              #7
              Re: working with System.Xml.XmlD ocument.

              > .Load(reader)?[color=blue]
              > - 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
              >[/color]
              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


              Comment

              • jens Jensen

                #8
                Re: working with System.Xml.XmlD ocument.

                - Do you get the same thing if you .Load(myFilePat h) 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.



                Comment

                • Marc Gravell

                  #9
                  Re: working with System.Xml.XmlD ocument.

                  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";(packin g the xml into a string")
                  xmlIn.LoadXml(s tr);

                  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


                  Comment

                  • Marc Gravell

                    #10
                    Re: working with System.Xml.XmlD ocument.

                    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("<x ml>?</xml>"); // the character in the middle here is dagger
                    (0134 decimal)
                    doc.Save("d:\\t est.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


                    Comment

                    • Marc Gravell

                      #11
                      Re: working with System.Xml.XmlD ocument.

                      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


                      Comment

                      • jens Jensen

                        #12
                        Re: working with System.Xml.XmlD ocument.

                        Ok
                        Many thanks. I will do what you said.
                        JJ


                        Comment

                        • jens Jensen

                          #13
                          Re: working with System.Xml.XmlD ocument.


                          "Marc Gravell" <mgravell@rm.co m> skrev i en meddelelse
                          news:%23977fvyK GHA.984@tk2msft ngp13.phx.gbl.. .[color=blue]
                          > 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
                          >[/color]


                          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?


                          Comment

                          • Marc Gravell

                            #14
                            Re: working with System.Xml.XmlD ocument.

                            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


                            Comment

                            • jens Jensen

                              #15
                              Re: working with System.Xml.XmlD ocument.

                              > Very curious. About this time I would be installing ehtereal... I'd be[color=blue]
                              > 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
                              >
                              >[/color]

                              Good questions, i will investigate.


                              Comment

                              Working...