Total members 11889 |It is currently Thu Mar 28, 2024 9:11 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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




Author:
Proficient
User avatar Posts: 280
Have thanks: 1 time

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.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : outputstream to inputstream
 Convert outputstream to inputstream     -  



Topic Tags

Java Files and I/O






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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