當前位置: 首頁>>代碼示例>>Java>>正文


Java Element.getChildText方法代碼示例

本文整理匯總了Java中org.jdom.Element.getChildText方法的典型用法代碼示例。如果您正苦於以下問題:Java Element.getChildText方法的具體用法?Java Element.getChildText怎麽用?Java Element.getChildText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jdom.Element的用法示例。


在下文中一共展示了Element.getChildText方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseSearchResult

import org.jdom.Element; //導入方法依賴的package包/類
private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));

    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();

    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song =  root.getChildText("LyricSong", ns);
    String artist =  root.getChildText("LyricArtist", ns);

    return new LyricsInfo(lyric, artist, song);
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:14,代碼來源:LyricsService.java

示例2: addImagePlanning

import org.jdom.Element; //導入方法依賴的package包/類
public static void addImagePlanning(String dbname, File planningFile) throws Exception {
    // create xml reader
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    doc = builder.build(planningFile);
    Element atts = doc.getRootElement();
    // check format first
    if (atts.getName().equalsIgnoreCase("imageplanning")) {
        // connect to database
        Connection conn = DriverManager.getConnection("jdbc:h2:~/.sumo/" + dbname + ";AUTO_SERVER=TRUE", "sa", "");
        Statement stat = conn.createStatement();
        String sql = "create table if not exists IMAGEPLAN (IMAGE VARCHAR(255), URL VARCHAR(1024), STARTDATE VARCHAR(255), ENDDATE VARCHAR(255), AREA VARCHAR(1024), ACTION VARCHAR(2048))";
        stat.execute(sql);
        // clear table before filling it in
        stat.execute("DELETE FROM IMAGEPLAN");
        // scan through images
        for (Object o : atts.getChildren("Image")) {
            Element element = (Element) o;
            // create sql statement
            sql = "INSERT INTO IMAGEPLAN VALUES('" + element.getChildText("name") + "', '" + element.getChildText("url") + "', '" + element.getChildText("startDate") + "', '" + element.getChildText("endDate") + "', '" + element.getChildText("area") + "', '" + element.getChildText("action") + "');";
            stat.execute(sql);
        }
        stat.close();
        conn.close();
    } else {
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                JOptionPane.showMessageDialog(null, "Format not supported", "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }

}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:35,代碼來源:H2Fetcher.java

示例3: fromXML

import org.jdom.Element; //導入方法依賴的package包/類
/**
 * Given xml representation of HIT converts them into an array of hits
 * @throws IOException
 */
public static Hit[] fromXML(String xml) throws IOException, JDOMException {
  SAXBuilder saxBuilder = new SAXBuilder(false);
  org.jdom.Document jdomDoc = saxBuilder.build(new StringReader(xml));
  Element rootElement = jdomDoc.getRootElement();
  if(!rootElement.getName().equalsIgnoreCase(HITS)) {
    throw new IOException("Root element must be " + HITS);
  }

  // rootElement is HITS
  // this will internally contains instances of HIT
  List<?> hitsChildren = rootElement.getChildren(HIT);
  Hit[] hits = new Hit[hitsChildren.size()];

  for(int i = 0; i < hitsChildren.size(); i++) {
    Element hitElem = (Element)hitsChildren.get(i);
    int startOffset = Integer.parseInt(hitElem.getChildText(START_OFFSET));
    int endOffset = Integer.parseInt(hitElem.getChildText(END_OFFSET));
    String docID = hitElem.getChildText(DOC_ID);
    String annotationSetName = hitElem.getChildText(ANNOTATION_SET_NAME);
    String queryString = hitElem.getChildText(QUERY);

    Element patternAnnotations = hitElem.getChild(PATTERN_ANNOTATIONS);
    if(patternAnnotations == null) {
      hits[i] = new Hit(docID, annotationSetName, startOffset, endOffset, queryString);
      continue;
    }

    List<?> patAnnots = patternAnnotations.getChildren(PATTERN_ANNOTATION);
    List<PatternAnnotation> patAnnotsList = new ArrayList<PatternAnnotation>();
    for(int j = 0; j < patAnnots.size(); j++) {
      Element patAnnot = (Element)patAnnots.get(j);
      PatternAnnotation pa = new PatternAnnotation();
      pa.setStOffset(Integer.parseInt(patAnnot.getChildText(START)));
      pa.setEnOffset(Integer.parseInt(patAnnot.getChildText(END)));
      pa.setPosition(Integer.parseInt(patAnnot.getChildText(POSITION)));
      pa.setText(patAnnot.getChildText(TEXT));
      pa.setType(patAnnot.getChildText(TYPE));

      // we need to find out its features
      Element featuresElem = patAnnot.getChild(FEATURES);
      // more than one features possible
      List<?> featuresElemsList = featuresElem.getChildren(FEATURE);
      for(int k = 0; k < featuresElemsList.size(); k++) {
        Element featureElem = (Element)featuresElemsList.get(k);
        String key = featureElem.getChildText(KEY);
        String value = featureElem.getChildText(VALUE);
        pa.addFeature(key, value);
      }
      patAnnotsList.add(pa);
    }

    String patternText = hitElem.getChildText(PATTERN_TEXT);
    int leftCSO = Integer.parseInt(hitElem
            .getChildText(LEFT_CONTEXT_START_OFFSET));
    int rightCEO = Integer.parseInt(hitElem
            .getChildText(RIGHT_CONTEXT_END_OFFSET));

    hits[i] = new Pattern(docID, annotationSetName, patternText, startOffset, endOffset,
            leftCSO, rightCEO, patAnnotsList, queryString);
  }
  return hits;
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:67,代碼來源:Parser.java


注:本文中的org.jdom.Element.getChildText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。