org.jdom2.Element.getText()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中org.jdom2.Element.getText()方法的一些代码示例,展示了Element.getText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getText()方法的具体详情如下:
包路径:org.jdom2.Element
类名称:Element
方法名:getText

Element.getText介绍

[英]Returns the textual content directly held under this element as a string. This includes all text within this single element, including whitespace and CDATA sections if they exist. It's essentially the concatenation of all Text and CDATA nodes returned by #getContent. The call does not recurse into child elements. If no textual value exists for the element, an empty string is returned.
[中]以字符串形式返回直接保存在此元素下的文本内容。这包括单个元素中的所有文本,包括空格和CDATA部分(如果存在)。它本质上是#getContent返回的所有文本和CDATA节点的串联。调用不会递归到子元素中。如果元素不存在文本值,则返回空字符串。

代码示例

代码示例来源:origin: gocd/gocd

private List<File> parseFiles(Element filesElement, String fileType) {
  List files = filesElement.getChild(fileType).getChildren("file");
  List<File> modifiedFiles = new ArrayList<>();
  for (Iterator iterator = files.iterator(); iterator.hasNext();) {
    Element node = (Element) iterator.next();
    modifiedFiles.add(new File(org.apache.commons.lang3.StringEscapeUtils.unescapeXml(node.getText())));
  }
  return modifiedFiles;
}

代码示例来源:origin: gocd/gocd

private Modification parseLogEntry(Element logEntry, String path) throws ParseException {
  Element logEntryPaths = logEntry.getChild("paths");
  if (logEntryPaths == null) {
    /* Path-based access control forbids us from learning
     * details of this log entry, so skip it. */
    return null;
  }
  Date modifiedTime = convertDate(logEntry.getChildText("date"));
  String author = logEntry.getChildText("author");
  String comment = logEntry.getChildText("msg");
  String revision = logEntry.getAttributeValue("revision");
  Modification modification = new Modification(author, comment, null, modifiedTime, revision);
  List paths = logEntryPaths.getChildren("path");
  for (Iterator iterator = paths.iterator(); iterator.hasNext();) {
    Element node = (Element) iterator.next();
    if (underPath(path, node.getText())) {
      ModifiedAction action = convertAction(node.getAttributeValue("action"));
      modification.createModifiedFile(node.getText(), null, action);
    }
  }
  return modification;
}

代码示例来源:origin: org.jdom/jdom

/**
 * Returns the textual content of the named child element, or null if
 * there's no such child. This method is a convenience because calling
 * <code>getChild().getText()</code> can throw a NullPointerException.
 *
 * @param  cname                the name of the child
 * @return                     text content for the named child, or null if
 *                             no such child
 */
public String getChildText(final String cname) {
  final Element child = getChild(cname);
  if (child == null) {
    return null;
  }
  return child.getText();
}

代码示例来源:origin: pwm-project/pwm

public StringArrayValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey key )
  {
    final List valueElements = settingElement.getChildren( "value" );
    final List<String> values = new ArrayList<>();
    for ( final Object loopValue : valueElements )
    {
      final Element loopValueElement = ( Element ) loopValue;
      final String value = loopValueElement.getText();
      values.add( value );
    }
    return new StringArrayValue( values );
  }
};

代码示例来源:origin: rometools/rome

protected void parseCollectionElement(final Element element) throws ProponoException {
  setHref(element.getAttribute("href").getValue());
  final Element titleElem = element.getChild("title", AtomService.ATOM_FORMAT);
  if (titleElem != null) {
    setTitle(titleElem.getText());
    if (titleElem.getAttribute("type", AtomService.ATOM_FORMAT) != null) {
      setTitleType(titleElem.getAttribute("type", AtomService.ATOM_FORMAT).getValue());
    }
  }
  final List<Element> acceptElems = element.getChildren("accept", AtomService.ATOM_PROTOCOL);
  if (acceptElems != null && !acceptElems.isEmpty()) {
    for (final Element acceptElem : acceptElems) {
      addAccept(acceptElem.getTextTrim());
    }
  }
  // Loop to parse <app:categories> element to Categories objects
  final List<Element> catsElems = element.getChildren("categories", AtomService.ATOM_PROTOCOL);
  for (final Element catsElem : catsElems) {
    final Categories cats = new Categories(catsElem, baseURI);
    addCategories(cats);
  }
}

代码示例来源:origin: org.openfuxml/ofx-util

private Element mergeRecursive(Element rootElement, XPath xpath) throws OfxInternalProcessingException
{
  try
  {
    List<?> list = xpath.selectNodes(rootElement);
    logger.debug(list.size()+" sections");
    
    for (Iterator<?> iter = list.iterator(); iter.hasNext();)
    {
      Element e = (Element) iter.next();
      boolean noChilds = (e.getChildren().size()==0);
      boolean noContent = (e.getText().length()==0);
      logger.trace(e.getName()+" "+e.getChildren().size()+" "+e.getText().length());
      if(noChilds && noContent){e.detach();}
      else{e.setText(e.getTextTrim());}
    }
  }
  catch (JDOMException e) {logger.error("",e);}
  return rootElement;
}

代码示例来源:origin: jpos/jPOS-EE

/**
 * Parses a JDOM Element as defined in
 * <a href="http://jpos.org/minigl.dtd">minigl.dtd</a>
 */
public void fromXML (Element elem) throws ParseException {
  setDetail (elem.getChildTextTrim ("detail"));
  setTags   (new Tags(elem.getChildTextTrim ("tags")));
  setCredit ("credit".equals (elem.getAttributeValue("type")));
  setLayer(toShort(elem.getAttributeValue("layer")));
  setAmount(new BigDecimal (elem.getChild ("amount").getText()));
}
/**

代码示例来源:origin: org.jdom/jdom

/**
 * Returns the textual content of the named child element, or null if
 * there's no such child.
 * 
 * @param cname
 *        the name of the child
 * @param ns
 *        the namespace of the child. A null implies Namespace.NO_NAMESPACE.
 * @return text content for the named child, or null if no such child
 */
public String getChildText(final String cname, final Namespace ns) {
  final Element child = getChild(cname, ns);
  if (child == null) {
    return null;
  }
  return child.getText();
}

代码示例来源:origin: edu.ucar/cdm

private void addAttributeIfExists(Element elem, String name, Variable v, boolean isDoubleArray) {
 Element child = elem.getChild(name);
 if (child == null) return;
 if (isDoubleArray) {
  List<Element> vElems = child.getChildren();
  List<Double> values = new ArrayList<Double>();
  for (Element ve : vElems) {
   String valueS = ve.getText().trim();
   try {
    values.add(Double.parseDouble(valueS));
   } catch (NumberFormatException e) {  }
   }
  Attribute att = new Attribute(name, values);
  v.addAttribute(att);
 } else {
  String value = child.getText().trim();
  Attribute att = new Attribute(name, value);
  v.addAttribute(att);
 }
}

代码示例来源:origin: pwm-project/pwm

public NumericArrayValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey input )
  {
    final List<Long> returnList = new ArrayList<>(  );
    final List<Element> valueElements = settingElement.getChildren( "value" );
    for ( final Element element : valueElements )
    {
      final String strValue = element.getText();
      final Long longValue = Long.parseLong( strValue );
      returnList.add( longValue );
    }
    return new NumericArrayValue( returnList );
  }
};

代码示例来源:origin: com.atlassian.maven.plugins/maven-jgitflow-plugin

public boolean apply(Element input)
  {
    Element child = input.getChild(name, ns);
    return (child == null) ? value.equals("") : value.equals(child.getText());
  }
};

代码示例来源:origin: edu.ucar/netcdf

private void addAttributeIfExists(Element elem, String name, Variable v, boolean isDoubleArray) {
 Element child = elem.getChild(name);
 if (child == null) return;
 if (isDoubleArray) {
  List<Element> vElems = child.getChildren();
  List<Double> values = new ArrayList<Double>();
  for (Element ve : vElems) {
   String valueS = ve.getText();
   try {
    values.add(Double.parseDouble(valueS));
   } catch (NumberFormatException e) {  }
   }
  Attribute att = new Attribute(name, values);
  v.addAttribute(att);
 } else {
  String value = child.getText();
  Attribute att = new Attribute(name, value);
  v.addAttribute(att);
 }
}

代码示例来源:origin: pwm-project/pwm

public OptionListValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey key )
      throws PwmOperationalException
  {
    final List valueElements = settingElement.getChildren( "value" );
    final Set<String> values = new TreeSet<>();
    for ( final Object loopValue : valueElements )
    {
      final Element loopValueElement = ( Element ) loopValue;
      final String value = loopValueElement.getText();
      if ( value != null && !value.trim().isEmpty() )
      {
        values.add( value );
      }
    }
    return new OptionListValue( values );
  }
};

代码示例来源:origin: com.xebialabs.cloud/overcast

public static String getElementText(Element parent, String localName, Namespace ns) {
  if (parent == null) {
    throw new IllegalArgumentException("parent element not found");
  }
  Element child = parent.getChild(localName, ns);
  if (child == null) {
    throw new IllegalArgumentException(String.format("child element '%s' not found", localName));
  }
  return child.getText();
}

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

protected WireFeed parseChannel(Element rssRoot)  {
  Channel channel = (Channel) super.parseChannel(rssRoot);
  Element eChannel = rssRoot.getChild("channel",getRSSNamespace());
  List eCats = eChannel.getChildren("category",getRSSNamespace());
  channel.setCategories(parseCategories(eCats));
  Element eTtl = eChannel.getChild("ttl",getRSSNamespace());
  if (eTtl!=null && eTtl.getText() != null ) {
    Integer ttlValue = null;        
    try{
       ttlValue = new Integer(eTtl.getText());
    } catch(NumberFormatException nfe ){ 
      ; //let it go by
    }
    if (ttlValue != null) {
      channel.setTtl(ttlValue.intValue());
    }
  }
  return channel;
}

代码示例来源:origin: net.sf.cuf/cuf-swing

/**
 * Returns the text of last title child of the handed element in
 * the current language or null, if no title child was found.
 * @param pElement the element we start searching from
 * @return null or the text of the title element
 */
public String getTitle(final Element pElement)
{
  String title= null;
  for (final Object o : pElement.getChildren(TITLE_ELEMENT))
  {
    Element titleElement = (Element) o;
    if (isSameLanguage(titleElement))
    {
      title = titleElement.getText();
    }
  }
  return title;
}

代码示例来源:origin: Unidata/thredds

private String getParam( String name) {
 Element elem = rootElem;
 if (elem == null) return null;
 StringTokenizer stoke = new StringTokenizer(name, ".");
 while (stoke.hasMoreTokens()) {
  String toke = stoke.nextToken();
  elem = elem.getChild(toke);
  if (null == elem)
   return null;
 }
 String text =  elem.getText();
 return (text == null) ? null : text.trim();
}

代码示例来源:origin: rometools/rome

@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
  final Channel channel = (Channel) super.parseChannel(rssRoot, locale);
  final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
  final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
  channel.setCategories(parseCategories(categories));
  final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
  if (ttl != null && ttl.getText() != null) {
    final Integer ttlValue = NumberParser.parseInt(ttl.getText());
    if (ttlValue != null) {
      channel.setTtl(ttlValue);
    }
  }
  return channel;
}

代码示例来源:origin: net.sf.cuf/cuf-swing

/**
 * Returns the text of last title child of the handed element in
 * the current language or null, if no title child was found.
 * @param pElement the element we start searching from
 * @return null or the text of the title element
 */
public static String getTitleDefaultLocale(final Element pElement)
{
  String title= null;
  for (final Object o : pElement.getChildren(TITLE_ELEMENT))
  {
    Element titleElement = (Element) o;
    if (isSameLanguage(titleElement, Locale.getDefault()))
    {
      title = titleElement.getText();
    }
  }
  return title;
}

代码示例来源:origin: pwm-project/pwm

public StringValue fromXmlElement( final PwmSetting pwmSetting, final Element settingElement, final PwmSecurityKey key )
  {
    final Element valueElement = settingElement.getChild( "value" );
    return new StringValue( valueElement == null ? "" : valueElement.getText() );
  }
};

相关文章