how to eliminate whitespaces from an XML file

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

    how to eliminate whitespaces from an XML file

    we have written a C# program which generates an XML file from a
    Client computer and this file is being transfered to the Server
    side(using Socket programming). at the Server side we are first
    extracting the data from the XML file into a Dataset and using the
    method Dataset.ReadXml () we are trying to parse the nodes in the file.
    But on debugging the following exception arises---

    Unexpected XML declaration. The XML declaration must be the first node
    in the document, and no white space characters are allowed to appear
    before it. Line 59, position 16.

    According to us, the problem occurs when the file is being transfered
    from the client to the server, some extra bytes are also transfered.

    Is there any solution to the problem?


  • Martin Honnen

    #2
    Re: how to eliminate whitespaces from an XML file

    Eliza wrote:
    we have written a C# program which generates an XML file from a
    Client computer and this file is being transfered to the Server
    side(using Socket programming). at the Server side we are first
    extracting the data from the XML file into a Dataset and using the
    method Dataset.ReadXml () we are trying to parse the nodes in the file.
    But on debugging the following exception arises---
    >
    Unexpected XML declaration. The XML declaration must be the first node
    in the document, and no white space characters are allowed to appear
    before it. Line 59, position 16.
    >
    According to us, the problem occurs when the file is being transfered
    from the client to the server, some extra bytes are also transfered.
    >
    Is there any solution to the problem?
    How do you create the XML exactly and how do you transfer it to the
    server exactly? How do you receive the XML on the server? Somewhere you
    seem to insert white space but we can't tell unless you share the code
    you use.
    --

    Martin Honnen --- MVP XML

    Comment

    • Peter Flynn

      #3
      Re: how to eliminate whitespaces from an XML file

      Eliza wrote:
      we have written a C# program which generates an XML file from a
      Client computer and this file is being transfered to the Server
      side(using Socket programming). at the Server side we are first
      extracting the data from the XML file into a Dataset and using the
      method Dataset.ReadXml () we are trying to parse the nodes in the file.
      But on debugging the following exception arises---
      >
      Unexpected XML declaration. The XML declaration must be the first node
      in the document, and no white space characters are allowed to appear
      before it. Line 59, position 16.
      >
      According to us, the problem occurs when the file is being transfered
      from the client to the server, some extra bytes are also transfered.
      >
      Is there any solution to the problem?
      Use software that does not add extra bytes :-)

      But what is interesting is that the error is reported at line 59:16.
      This implies that there are 58 blank lines being inserted before the XML
      Declaration, which doesn't sound very likely. Character position 16 in
      the default XML Declaration is...
      <?xml version="1.0"?>
      123456789012345 6
      ....the first character of the version number, which is also an odd place
      to report an error. I would have expected position 6, the point at which
      it becomes clear to the parser that the XML Declaration PI name is 'xml'.

      Are there really 58 blank lines at the start of the file? Or is the file
      perhaps 59 lines long, ending with an end-tag for the root element type
      which happens to be 15 characters long?

      As Martin said, unless you can give us more information, it's not
      possible to give a useful answer.

      ///Peter

      Comment

      Working...