Sunday, November 7, 2010

Convert an InputStream to XML

For that we can use DocumentBuilder class in java. By using the method parse(InputStream) ;A new DOM Document object will return.

InputStream input;

DocumentBuilderFactory factory
= DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document dc= parser.parse(input);

In the above code segment,by using the created Document object,the corresponding XML file for the inputStream can be accessed.

References:

http://www.w3schools.com/dom/dom_intro.asp

http://download.oracle.com/javase/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html

No comments:

Post a Comment