0

我正在使用 NekoHTML 来解析一些 HTML 文件的内容..

除了将文档对象的内容提取到某个字符串之外,一切都很好。

我试过用

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);

但似乎没有返回。

4

2 回答 2

0

Oracle App server 10.3.1.4 http://m-hewedy.blogspot.com/2011/04/oracle-application-server-overrides.html中的问题

于 2011-04-30T14:11:28.027 回答
0

可能的解决方案:

//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);  

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

参见e) 将 DOM 序列化为 FileOutputStream 以生成 xml 文件 "book.xml"

于 2011-06-22T12:37:25.503 回答