本文整理了Java中org.jsoup.nodes.Element.classNames()
方法的一些代码示例,展示了Element.classNames()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.classNames()
方法的具体详情如下:
包路径:org.jsoup.nodes.Element
类名称:Element
方法名:classNames
[英]Get all of the element's class names. E.g. on element
, returns a set of two elements "header", "gray". Note that modifications to this set are not pushed to the backing class attribute; use the #classNames(java.util.Set) method to persist them.
[中]
代码示例来源:origin: org.jsoup/jsoup
/**
Add a class name to this element's {@code class} attribute.
@param className class name to add
@return this element
*/
public Element addClass(String className) {
Validate.notNull(className);
Set<String> classes = classNames();
classes.add(className);
classNames(classes);
return this;
}
代码示例来源:origin: org.jsoup/jsoup
/**
Remove a class name from this element's {@code class} attribute.
@param className class name to remove
@return this element
*/
public Element removeClass(String className) {
Validate.notNull(className);
Set<String> classes = classNames();
classes.remove(className);
classNames(classes);
return this;
}
代码示例来源:origin: org.jsoup/jsoup
/**
Toggle a class name on this element's {@code class} attribute: if present, remove it; otherwise add it.
@param className class name to toggle
@return this element
*/
public Element toggleClass(String className) {
Validate.notNull(className);
Set<String> classes = classNames();
if (classes.contains(className))
classes.remove(className);
else
classes.add(className);
classNames(classes);
return this;
}
代码示例来源:origin: org.jsoup/jsoup
/**
* Get a CSS selector that will uniquely select this element.
* <p>
* If the element has an ID, returns #id;
* otherwise returns the parent (if any) CSS selector, followed by {@literal '>'},
* followed by a unique selector for the element (tag.class.class:nth-child(n)).
* </p>
*
* @return the CSS Path that can be used to retrieve the element in a selector.
*/
public String cssSelector() {
if (id().length() > 0)
return "#" + id();
// Translate HTML namespace ns:tag to CSS namespace syntax ns|tag
String tagName = tagName().replace(':', '|');
StringBuilder selector = new StringBuilder(tagName);
String classes = StringUtil.join(classNames(), ".");
if (classes.length() > 0)
selector.append('.').append(classes);
if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node
return selector.toString();
selector.insert(0, " > ");
if (parent().select(selector.toString()).size() > 1)
selector.append(String.format(
":nth-child(%d)", elementSiblingIndex() + 1));
return parent().cssSelector() + selector.toString();
}
代码示例来源:origin: vsch/flexmark-java
} else {
final Set<String> classNames = element.classNames();
if (!classNames.isEmpty()) {
for (String clazz : classNames) {
代码示例来源:origin: mangstadt/ez-vcard
/**
* Gets the element's CSS classes.
* @return the CSS classes
*/
public Set<String> classNames() {
return element.classNames();
}
代码示例来源:origin: stackoverflow.com
String html="<<your html content>>";
Document doc = Jsoup.parse(html);
Element ele=doc.getElementsContainingOwnText("Hello World").first.clone(); //get tag containing Hello world
HashSet<String>class=ele.classNames(); //gives you the classnames of element containing Hello world
代码示例来源:origin: astamuse/asta4d
public Element classNames(Set<String> classNames) {
return originElement.classNames(classNames);
}
代码示例来源:origin: astamuse/asta4d
public Set<String> classNames() {
return originElement.classNames();
}
代码示例来源:origin: astamuse/asta4d
@Override
protected void configure(Element elem, String attrName, Object attrValue) {
elem.removeAttr(ExtNodeConstants.ATTR_DATAREF_PREFIX_WITH_NS + attrName);
elem.removeAttr(attrName);
// for remove all class definition, we have to clear the
// classNames too.
if (attrName.equals("class")) {
elem.classNames().clear();
}
}
},
代码示例来源:origin: com.wandrell.velocity/maven-site-fixer
/**
* Finds a set of elements through a CSS selector and removes the received
* class from them, if they have it.
* <p>
* If the elements end without classes then the class attribute is also
* removed.
*
* @param root
* root element for the selection
* @param selector
* CSS selector for the elements with the class to remove
* @param className
* class to remove
*/
public final void removeClass(final Element root, final String selector,
final String className) {
final Iterable<Element> elements; // Elements selected
checkNotNull(root, "Received a null pointer as root element");
checkNotNull(selector, "Received a null pointer as selector");
checkNotNull(className, "Received a null pointer as className");
// Selects and iterates over the elements
elements = root.select(selector);
for (final Element element : elements) {
element.removeClass(className);
if (element.classNames().isEmpty()) {
element.removeAttr("class");
}
}
}
代码示例来源:origin: GistLabs/mechanize
public static String getAttributeValueOfJSoupElement(Element element, String attributeKey) {
if(attributeKey.startsWith("${") && attributeKey.endsWith("}")) {
if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_TEXT))
return element.text();
else if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_INNER_HTML))
return element.html();
else if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_HTML))
return element.outerHtml();
else if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_TAG_NAME))
return element.tagName();
else if(attributeKey.equals(HtmlSpecialAttributes.SPECIAL_ATTRIBUTE_CLASS_NAMES)) {
StringBuilder result = new StringBuilder();
for(String name : element.classNames()) {
if(result.length() > 0)
result.append(",");
result.append(name);
}
return result.toString();
}
else
return null;
}
else
return element.attr(attributeKey);
}
代码示例来源:origin: stackoverflow.com
Set<String> cssClasses = cssElement.classNames();
cssClasses.forEach( c -> result.append( '.' ).append( c ) );
result.append( ' ' );
代码示例来源:origin: mangstadt/ez-vcard
if (node instanceof Element) {
Element e = (Element) node;
if (e.classNames().contains("type")) {
代码示例来源:origin: JavaChat/OakBot
break;
case "span":
if (linkText != null && element.classNames().contains("ob-post-tag")) {
inTag = true;
代码示例来源:origin: mangstadt/ez-vcard
private void visit(Element element) {
boolean visitChildren = true;
Set<String> classNames = element.classNames();
for (String className : classNames) {
className = className.toLowerCase();
内容来源于网络,如有侵权,请联系作者删除!