This topic has been locked.
1 reply Latest Post - 2013-01-09T15:03:40Z by mburati
Pinned topic How to parse byte array to an XML??
Answered question This question has been answered.
Unanswered question This question has not been answered yet.
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 060000VQ202361 PostsACCEPTED ANSWER
Re: How to parse byte array to an XML??2013-01-09T15:03:40Z in response to SystemAdminAssuming 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:
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,
The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.