Java2 codes,problems ,discussions and solutions are here
Fri Oct 24, 2008 8:48 pm
Hi everyone,
What i am trying to do is to parse some xml being returned to me with
the following code:
DocumentBuilderFactory xmlResults = DocumentBuilderFactory.newInstanc();
DocumentBuilder docBuilder =xmlResults.newDocumentBuilder();
Document iterDoc = docBuilder.parse(in);
The xml is coming back to me as an outputstream though.right now i am
trying to get the outputstream from the HTTPUrlConnection by using
the .getOutputStream method. I then need to take this and convert it
into and inputstream so i can pass it to docBuilder.parse...I am having
problems following the websites that i have found...
I know i need to define a byte array
something like:ByteArrayOutputStream out = new ByteArrayOutputStream();
or would i want to use a regular byte array??
After i do this how to i take the output stream and store it in the
array then convert it to a inputstream
Fri Oct 24, 2008 8:49 pm
have you tried to do something like this?:
- Code:
DocumentBuilderFactory xmlResults = DocumentBuilderFactory.newInstanc();
DocumentBuilder docBuilder =xmlResults.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
docBuilder.parse(new InputSource(bais));
Document dom = docBuilder.getDocument();
I think you can convert the OutputStream to an ByteArrayInputStream
and after that use it to "parse" the XML.
Topic Tags
Java Files and I/O
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.