开发者

How to write contents of Document Object to String in NekoHTML?

I am using NekoHTML to parse contents of some HTML file..

Everything goes okay except for extracting the contents of the Document Object to some string.

I've tried uses

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResu开发者_Python百科lt result = new StreamResult(writer);
transformer.transform(source, result);

But nothing appears returned.


The problem where in Oracle App server 10.3.1.4 http://m-hewedy.blogspot.com/2011/04/oracle-application-server-overrides.html


Posible solution:

//this nekohtml  
DOMParser parser = new DOMParser();  
parser.parse(archivo);  


//this xerces  
OutputFormat format = new OutputFormat(parser.getDocument());   
format.setIndenting(true);  

//print xml for console 
//XMLSerializer serializer = new XMLSerializer(System.out, format); 

//save xml in string var 
OutputStream outputStream = new ByteArrayOutputStream(); 
XMLSerializer serializer = new XMLSerializer(outputStream, format); 

//process
serializer.serialize(parser.getDocument()); 


String xmlText = outputStream.toString();  

System.out.println(xmlText); 

//to generate a file output use fileoutputstream instead of system.out 
//XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File("book.xml")), format);  

Url: http://totheriver.com/learn/xml/xmltutorial.html#6.2

See e) Serialize DOM to FileOutputStream to generate the xml file "book.xml" .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜