×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    Writing Xml to output stream

    Hi All ,
    I have a situation where i have to generate an XML file and send it over Http in J2ME.Now for sending it over Http I need to obtain byte[] so as to write it to output stream.I do not want to store the generated xml in file system and than read it and convert it into the byte[].Is this possible?
    Last edited by ranjan.gururani; 2010-02-22 at 06:52.

  2. #2
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    69

    Re: Writing Xml to output stream

    Hii

    Check this!

    Nikesh~
    Enthusiastic
    Last edited by Enthusiastic; 2010-02-22 at 08:03.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    Re: Writing Xml to output stream

    I went through the link but again it saves the output to a file.In my case i need to convert Document object to byte array.It seems its not straight forward in J2ME.

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,104
    In your Java world, what type of object is your XML?

    Is it a String? Then you can use DataOutputStream.writeChars which requires a XML in UTF-16 big-endian encoding. Or you use OutputStream.write(byte[]) with String.getBytes("UTF-8") if your XML says it is in UTF-8 or US-ASCII.

    It is not a String? What about Object.toString()?

  5. #5
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    69

    Re: Writing Xml to output stream

    Hii ranjan,

    actually that link i've given to get idea hw can create xml... instead of saving into file u can get that xml as byte[] format...

    Nikesh~
    Enthusiastic

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Writing Xml to output stream

    Quote Originally Posted by ranjan.gururani View Post
    I went through the link but again it saves the output to a file.In my case i need to convert Document object to byte array.It seems its not straight forward in J2ME.
    Whether your writing to an OutputStream from a FileConnection, an HttpConnection, or to a ByteArrayOutputStream, or any other kind of OutputStream, the process is identical.

    If you particularly want a byte[], you could write the XML to a ByteArrayOutputStream, but you can equally write it directly to the OutputStream opened from the HttpConnection.

    Graham.

  7. #7
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    Thumbs up Re: Writing Xml to output stream

    Hi,
    Sorry All for acknowledging your contributions so late.I got fair idea by reading all your post.The solution i approached is like this.I used KXML to create a Document object and then using KXML serializer I wrote it to output Stream. I guess there
    was no other simple way to convert Document object into byte[] in J2ME

    Once again thanks to all for their suggestions.

Similar Threads

  1. XML writing and Appending the Problem
    By talk2mishal in forum Mobile Java General
    Replies: 3
    Last Post: 2008-09-19, 19:24
  2. generating an XML file..
    By mayankkedia in forum Symbian
    Replies: 0
    Last Post: 2007-01-10, 14:42
  3. Java SDK's Redirect application for viewing output stream
    By nkn_motoko in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2001-11-06, 20:01
  4. Java SDK's Redirect application for viewing output stream
    By nkn_motoko in forum Mobile Java General
    Replies: 0
    Last Post: 2001-11-06, 19:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •