I'm parsing a ServletRequest object(well, a HttpServletRequest really) Have 2 parameters there, one of them I know to have a value which is an XML file.
How can I retrieve that XML as Doc or byte[] or similar, rather than String?
I'm parsing a ServletRequest object(well, a HttpServletRequest really) Have 2 parameters there, one of them I know to have a value which is an XML file.
How can I retrieve that XML as Doc or byte[] or similar, rather than String?
You can convert String
to byte[]
easily enough using its getBytes()
function.
If you want a Doc, you'll have to parse it. To do that, you can get a DocumentBuilder
from DocumentBuilderFactory
and let that parse()
a ByteArrayOutputStream
wrapped around that byte array.
If you have a string which contains XML, you can parse that into a Document by parsing from a StringReader which wraps the String. Don't convert the String to bytes unless you can deal with the potential encoding issues.
builder.parse(new InputSource(new StringReader(theString))