开发者

How to get String content of Document object(including markup)?

开发者 https://www.devze.com 2023-02-22 21:55 出处:网络
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

Document doc = builder.newDocument();

//here append some children.... (this application should run on andoroid API 4) the problem is : how can I get the text content(including markup) of the "d开发者_运维技巧oc" ? I will appreciated if someone can give me some advice. Thanks~!


    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    t.setOutputProperty(OutputKeys.INDENT, "yes");
    StringWriter sw = new StringWriter();
    t.transform(new DOMSource(d), new StreamResult(sw));
    System.out.println(sw.toString());
0

精彩评论

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