久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何從 JDOM 獲取節(jié)點(diǎn)內(nèi)容

How to get node contents from JDOM(如何從 JDOM 獲取節(jié)點(diǎn)內(nèi)容)
本文介紹了如何從 JDOM 獲取節(jié)點(diǎn)內(nèi)容的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在使用 import org.jdom.* 編寫(xiě)一個(gè) java 應(yīng)用程序;

I'm writing an application in java using import org.jdom.*;

我的 XML 是有效的,但有時(shí)它包含 HTML 標(biāo)記.例如,像這樣:

My XML is valid,but sometimes it contains HTML tags. For example, something like this:

  <program-title>Anatomy &amp; Physiology</program-title>
  <overview>
       <content>
              For more info click <a href="page.html">here</a>
              <p>Learn more about the human body.  Choose from a variety of Physiology (A&amp;P) designed for complementary therapies.&amp;#160; Online studies options are available.</p>
       </content>
  </overview>
  <key-information>
     <category>Health &amp; Human Services</category>

所以我的問(wèn)題在于 <p > overview.content 節(jié)點(diǎn)內(nèi)的標(biāo)簽.

So my problem is with the < p > tags inside the overview.content node.

我希望這段代碼可以工作:

I was hoping that this code would work :

        Element overview = sds.getChild("overview");
        Element content = overview.getChild("content");

        System.out.println(content.getText());

但它返回空白.

如何從 overview.content 節(jié)點(diǎn)返回所有文本(嵌套標(biāo)簽和所有)?

How do I return all the text ( nested tags and all ) from the overview.content node ?

謝謝

推薦答案

content.getText() 提供即時(shí)文本,該文本僅對(duì)帶有文本內(nèi)容的葉子元素有用.

content.getText() gives immediate text which is only useful fine with the leaf elements with text content.

技巧是使用 org.jdom.output.XMLOutputter (帶文本模式 CompactFormat )

Trick is to use org.jdom.output.XMLOutputter ( with text mode CompactFormat )

public static void main(String[] args) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    String xmlFileName = "a.xml";
    Document doc = builder.build(xmlFileName);

    Element root = doc.getRootElement();
    Element overview = root.getChild("overview");
    Element content = overview.getChild("content");

    XMLOutputter outp = new XMLOutputter();

    outp.setFormat(Format.getCompactFormat());
    //outp.setFormat(Format.getRawFormat());
    //outp.setFormat(Format.getPrettyFormat());
    //outp.getFormat().setTextMode(Format.TextMode.PRESERVE);

    StringWriter sw = new StringWriter();
    outp.output(content.getContent(), sw);
    StringBuffer sb = sw.getBuffer();
    System.out.println(sb.toString());
}

輸出

For more info click<a href="page.html">here</a><p>Learn more about the human body. Choose from a variety of Physiology (A&amp;P) designed for complementary therapies.&amp;#160; Online studies options are available.</p>

請(qǐng)?zhí)剿髌渌?格式化 選項(xiàng)并在上面進(jìn)行修改根據(jù)您的需要編寫(xiě)代碼.

Do explore other formatting options and modify above code to your need.

封裝XMLOutputter格式選項(xiàng)的類(lèi).典型用戶可以使用getRawFormat()(不改變空白)、getPrettyFormat()(空白美化)、getCompactFormat()(空白歸一化)得到的標(biāo)準(zhǔn)格式配置."

"Class to encapsulate XMLOutputter format options. Typical users can use the standard format configurations obtained by getRawFormat() (no whitespace changes), getPrettyFormat() (whitespace beautification), and getCompactFormat() (whitespace normalization). "

這篇關(guān)于如何從 JDOM 獲取節(jié)點(diǎn)內(nèi)容的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Upload progress listener not fired (Google drive API)(上傳進(jìn)度偵聽(tīng)器未觸發(fā)(Google 驅(qū)動(dòng)器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無(wú)效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅(qū)動(dòng)api服務(wù)賬戶查看上傳文件到谷歌驅(qū)動(dòng)使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務(wù)帳號(hào)返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 午夜日韩精品 | 一区二区三区四区在线 | 国产成人一区二区三区精 | 亚洲国产偷 | 99re在线视频观看 | 久久久www成人免费无遮挡大片 | 免费在线播放黄色 | 国产精品成人一区二区三区 | 日朝毛片| 福利网址 | 一区二区三区中文字幕 | 91精品国产91久久综合桃花 | 国产在线1区| 国产精品一区二区久久久久 | www.47久久青青 | 欧美视频在线一区 | 日韩a视频 | 日日骚网 | 国产精品久久久乱弄 | 天天碰日日操 | 亚洲成人福利在线观看 | 亚洲成人综合在线 | 欧美性生活免费 | 天天色图| 男女搞网站| 欧美日韩在线一区二区 | 干干干日日日 | 四虎影院在线免费观看 | 精品久久久久一区二区国产 | 色综合久久天天综合网 | 狠狠干2020 | 国产成人网 | 日韩一区二区三区在线 | 一区二区三区免费网站 | 国产精品综合色区在线观看 | 日韩专区中文字幕 | 欧美国产日韩在线 | 精品无码久久久久国产 | 国产黄色在线观看 | 成人二区| 亚洲精品成人av久久 |