Topic
  • 1 reply
  • Latest Post - ‏2013-01-09T15:03:40Z by mburati
SystemAdmin
SystemAdmin
9029 Posts

Pinned topic How to parse byte array to an XML??

‏2013-01-09T11:47:02Z |
Can anybody suggest an idea about how to parse byte array to an XML? Since XML takes everything in String form, I require it to be passed in byte array form??
Updated on 2013-01-09T15:03:40Z at 2013-01-09T15:03:40Z by mburati
  • mburati
    mburati
    2568 Posts

    Re: How to parse byte array to an XML??

    ‏2013-01-09T15:03:40Z  
    Assuming you're using WEF (which this forum is for), then you likely want to use the following to parse XML when it's coming from something other than a String:

    com.bowstreet.util.XmlUtil.parseXml(Reader input);

    For example, from a file where you know you have UTF-8 encoded XML, you could do something like this:

    
    in = 
    
    new FileInputStream(fileName); Reader reader = 
    
    new InputStreamReader(in, 
    "UTF-8"); IXml val = XmlUtil.parseXml( reader );
    


    If you already have a byte[] of UTF-8 encoded characters, then it might look something like this (just typing this off the top of my head - haven't tried compiling it to make sure the syntax is exact and exceptions handled etc). Basically you want to get what you have into a Reader and then use the parseXml call that takes a reader.

    
    in = 
    
    new ByteArrayInputStream(bytes); reader = 
    
    new InputStreamReader(in, 
    "UTF-8"); IXml val = XmlUtil.parseXml( reader );
    


    I hope that info helps,
    ..Mike Burati
    http://www-10.lotus.com/ldd/pfwiki.nsf/
    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.