Thread: XML Byte Stream

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    57
    Rep Power
    11

    Unhappy XML Byte Stream


    Hi,

    I have an XML document which I need to pass to a webservice. The HttpWebRequest.Write method accepts a byte[] as the parameter.

    What is the best way to convert an XML document to a byte stream.

    Thanks,
    Ranjan Kumar
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    11
    Havent tested this but:

    byte[] Data;
    FileStream Stream = new FileStream(@"C:\\file.xml", FileMode.Open, FileAccess.Read);
    BinaryReader File = new BinaryReader(Stream);

    Data = File.ReadBytes(Stream.Length);
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    57
    Rep Power
    11

    XML Http Stream


    Hi,

    Thanks for the reply. I had tried that before but it does not work.

    By the way, do you know if there is a restriction on the size of a string. Because right now I am reading the data into a string and using the following:

    Byte[] buf = System.Text.Encoding.UTF8.GetBytes(strXML.ToString());

    to convert to bytes.

    This works fine.

    Thanks,

    Ranjan.
    Ranjan Kumar
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    11
    Can't see any reason it shouldn't work.

    As for the size of a string, I believe it's one byte under 2GB (the size of the positive portion of an int).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    57
    Rep Power
    11

    Wink XML Byte Stream


    Sorry Nem.... after doing some small changes it worked. I am sorry I forgot to mention that yesterday.

    Ranjan.
    Ranjan Kumar

IMN logo majestic logo threadwatch logo seochat tools logo