Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8094817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:55:12+00:00 2026-06-05T20:55:12+00:00

This is an example XML file that would come from the Android Client. <test>

  • 0

This is an example XML file that would come from the Android Client.

<test>
<to>Mee</to>
<from>Youuu</from>
<img src="http://www.domain.com/path/to/my/image.jpg" />
</test>

I have written a XML parser about this. My problem is while passing it to the Android Client, I need to have the image binary data instead of the image path. How can I accomplish this and how can I update the above said XML with the binary data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:55:14+00:00Added an answer on June 5, 2026 at 8:55 pm

    You could use Base64 to encode your image binary data (represented by a byte[]) and include it in the xml as CDATA.
    Then on the Android machine, you just decode it to a byte array, and render the image.

    You can use Apache Commons to encode/decode.

    Edit:

    You need to get a byte representation of the image data in order to convert it. See my example. This is using sun.misc.BASE64Decoder and sun.misc.BASE64Encoder, you may need to adapt depending on what you have at your disposal on Android (see Apache Commons).

    public class SO11096275 {
        public static byte[] readImage(URL url) throws IOException {
            final ByteArrayOutputStream bais = new ByteArrayOutputStream();
            final InputStream is = url.openStream();
            try {
                int n;
                byte[] b = new byte[4096];
                while ((n = is.read(b)) > 0) {
                    bais.write(b, 0, n);
                }
                return bais.toByteArray();
            } finally {
                if (is != null) {
                    is.close();
                }
            }
        }
    
        public static void main(String[] args) throws Exception {
            URL url = new URL("http://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png");
            byte[] imgData = readImage(url);
            String imgBase64 = new BASE64Encoder().encode(imgData);
            System.out.println(imgBase64);
            byte[] decodedData = new BASE64Decoder().decodeBuffer(imgBase64);
            FileUtils.writeByteArrayToFile(new File("/path/to/wikipedia-logo.png"), decodedData); // apache commons
        }
    }
    

    Then you have your image data as a string in imgBase64, you just have to append a node to your xml using the DOM implementation you want, for example dom4j. There are methods to add CDATA to the XML. Finally, on your Android, you just need to retrieve the node content and you’re good to decode it like above and do what you want with the image.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
This is an example xml from MSDN <?xml version=1.0?> <!-- A fragment of a
So, this example comes right from MSDN. http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.readelementcontentasbase64.aspx Pretty much the only thing I
Here is an example bit from the xml file: <array> <dict> <key>Name</key> <string>Joe Smith</string>
I have a little script that replace some text, that come from a xml
Here is an example of a parsed xml file I'm working with that tabs
I have an XML file that I deserialize into a class object. This class
What would be your take on a xml file that contains certain elements, that
I have a string in an XML file that looks similar to this: M:Namespace.Class.Method(Something
In my android application I have to a read an XML file that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.