org.jdom.Element.toString()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(168)

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

Element.toString介绍

[英]This returns a String representation of the Element, suitable for debugging. If the XML representation of the Element is desired, org.jdom.output.XMLOutputter#outputString(Element)should be used.
[中]这将返回适合调试的ElementString表示形式。如果需要Element的XML表示形式,请单击org。jdom。输出应使用XMLOutputter#outputString(元素)。

代码示例

代码示例来源:origin: stackoverflow.com

Document document = Jsoup.connect(url).get();
 Elements eles = doc.select("pre");
 for (Element ele : eles) {
   System.out.println(ele.toString());
 }

代码示例来源:origin: locationtech/geowave

public static Element writeElementList(final String tag, final Collection<?> c) {
 final Element el = new Element(tag);
 try {
  el.addContent(c);
 } catch (final IllegalAddException e) {
  LOGGER.warn(e + ":  " + el.toString(), e);
 }
 return el;
}

代码示例来源:origin: stackoverflow.com

for (int i = 0; i < elements.size(); i++) {
  Element sibling = siblings.get(i);
  if ("table".equals(sibling.tagName())) {
    siblings.remove(i);
    Element button = Jsoup.parse("<button type='button'>Click Me!</button>");
    sibling = button;
    sb.append(sibling.toString());
   } 
  else {
    sb.append(sibling.toString());
  }
}

代码示例来源:origin: stackoverflow.com

public static List<String> parseForMeta(String htmlText) {
  Document jsDocument = Jsoup.parse(htmlText);
  Elements metaElements = jsDocument.select("meta[name]");
  List<String> metaList = new ArrayList<String>();
  for (Element element : metaElements) {
    metaList.add(element.toString());
  }
  return metaList;
 }

代码示例来源:origin: stackoverflow.com

Document doc = Jsoup.connect(...).get();

for( Element e : doc.select("a[href]") ) // Select all 'a'-Tags with 'href' attribute
{
  String wholeTag = e.toString(); // Get a string as the element is

  /* No you you can use the html - in this example for a simple output */
  System.out.println(wholeTag);
}

代码示例来源:origin: stackoverflow.com

for(SyndEntry entry : feed.getEntries()) {
  for (Element element : entry.getForeignMarkup()) {
    System.out.println("element: " + element.toString());
  }
}

代码示例来源:origin: stackoverflow.com

Elements elements = doc.select("h1,h2,h3,h4,h5");
for (Element element : elements) {
  StringBuilder sb = new StringBuilder(element.toString());
  Element next = element.nextElementSibling();
  while (next != null && !next.tagName().startsWith("h")) {
   sb.append(next.toString()).append("\n");
   next = next.nextElementSibling();
  }
  System.out.println(sb);
}

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

@Override
public void ingest(Context context, DSpaceObject dso, Element root, boolean createMissingMetadataFields)
  throws CrosswalkException, IOException, SQLException, AuthorizeException {
  if (!(root.getName().equals("premis"))) {
    throw new MetadataValidationException("Wrong root element for PREMIS: " + root.toString());
  }
  ingest(context, dso, root.getChildren(), createMissingMetadataFields);
}

代码示例来源:origin: stackoverflow.com

Elements divs = doc.select("div.sports_FfCell"); //gets the div part that has the information you want. 

for (Element div : divs) {      
   if (div.toString().contains("market")) //there is a market tag for the table labels (sports_FfCell market).
    System.out.print(div.text() + " - "); //no new line after the winner text.
   else
    System.out.println(div.text().replace("MULTI", "- ")); //it gets the MULTI part too, so i replace it.
}

代码示例来源:origin: stackoverflow.com

String html="<html><body><div class=\"main\">" + "<div class=\"sub\"> sub </div>" + "main </div></body></html>";
 Document doc=Jsoup.parse(html);
 Elements divs=doc.select("*");
 for(Element div : divs){
   System.out.println(div.tag() + ":\n" + div.toString());
   System.out.println("---");
 }

代码示例来源:origin: stackoverflow.com

URL url = new URL("http://www.myurl.com");
Document doc = Jsoup.parse(url, 3000);
// This should work now
Element tables = doc.select("table tr .id");
// This propably should work too
Element tables2 = doc.select("table tr[class*=id]");

for(Element table : tables)
{
   System.out.println(table.toString());
}

代码示例来源:origin: stackoverflow.com

private String getTextContent(Element elem) {
  String text = elem.getContent().toString();

  final List<Element> children = elem.getChildElements();
  for (Element child : children) {
    text = text.replace(child.toString(), "");
  }
  return text;
}

代码示例来源:origin: stackoverflow.com

final String html = "<b><script>your script here</script></b>";
Document doc = Jsoup.parse(html);

for( Element element : doc.select("script") )
{
  element.replaceWith(TextNode.createFromEncoded(element.toString(), null));
}

System.out.println(doc);

代码示例来源:origin: stackoverflow.com

protected void onPostExecute(Elements result) 
{
  print("\nLinks: (%d)", result.size());

  for (Element link : result) 
  {
    //view.setText((CharSequence) link);
    view.setText(link.toString());
    print(" * a: <%s>  (%s)", link.attr("abs:href"), trim(link.text(), 35));
  }
}

代码示例来源:origin: stackoverflow.com

Elements e = doc.select("table#scheuletbl > tbody > tr > td");
for (Element el : e) {
  if (el.hasClass("separator2")) System.out.println(el.text()); // cinema name
  else if (el.toString().contains("colspan=\"2\"")) System.out.println(el.text()); // date
  else if (el.hasAttr("rel")) System.out.println(el.text()); // times
}

代码示例来源:origin: stackoverflow.com

public String escapeHtml(String source) {
  Document doc = Jsoup.parseBodyFragment(source);
  Elements elements = doc.select("b");
  for (Element element : elements) {
    element.replaceWith(new TextNode(element.toString(),""));
  }
  return Jsoup.clean(doc.body().toString(), new Whitelist().addTags("a").addAttributes("a", "href", "name", "rel", "target"));
}

代码示例来源:origin: stackoverflow.com

Document documentImage2 = Jsoup.connect(urls[0]).get();
// Using Elements to get the class data
Element div = documentImage2.select("div[class=content]").get(1);
Document doc_i = Jsoup.parse(div.toString());
Elements image = doc_i.select("img");
String imgSrcImage2 = image.html();

代码示例来源:origin: net.sf.taverna.t2.translators/biomart-activity-translator

@Test
public void testCreateConfigTypeProcessor()
    throws ActivityTranslationException {
  Element bean = translator
      .createConfigType(biomartProcessor);
  assertNotNull(bean);
  assertEquals(biomartProcessor.getQueryElement(null).toString(), bean.toString());
}

代码示例来源:origin: net.sf.taverna.t2.activities/biomart-activity-translator

@Test
public void testCreateConfigTypeProcessor()
    throws ActivityTranslationException {
  Element bean = translator
      .createConfigType(biomartProcessor);
  assertNotNull(bean);
  assertEquals(biomartProcessor.getQueryElement(null).toString(), bean.toString());
}

代码示例来源:origin: net.sf.taverna.t2/biomart-activity-translator

@Test
public void testCreateConfigTypeProcessor()
    throws ActivityTranslationException {
  BiomartActivityConfigurationBean bean = translator
      .createConfigType(biomartProcessor);
  assertNotNull(bean);
  assertEquals(biomartProcessor.getQueryElement(null).toString(), bean.getQuery().toString());
}

相关文章

微信公众号

最新文章

更多