Elements Class __js of Jsoup

Source: Internet
Author: User
Tags addall tag name tagname

First, Introduction

This class is located under the Select package, directly inherits from object, all implements the interface to have cloneable, iterable<element>, Collection<element>, list<element >

class declaration: public class Elements extends Object implements List<element>, cloneable

You can use the Element.select (String) method to get the Elements object.

second, the construction method

1. Public Elements() Default construction method
2, public Elements(int initialcapacity) specifies an initial capacity to create a Elements object.

3. Public Elements(collection<element> Elements) creates a Elements object using a known set of elements.

4. Public Elements(list<element> Elements) creates a Elements object using the List collection of known elements.

5. Public Elements(Element ... Elements) creates a Elements object using a variable parameter list of the known elements.

third, the method in detail

1. Public Elements Clone ()

2. The public string attr(String attributekey) obtains the first matching element based on the key (this property is matched).

3. Returns true if any of the element matches (with this property) exist in the set of public boolean hasattr(String attributekey) elements.

4. Public Elements attr(String attributekey, String attributevalue) sets the value of all elements that match the Attributekey key to AttributeValue.

5, public Elements removeattr(String attributekey) Remove any one of the matching elements in the element set

6. The public Elements addclass(String className) adds className to the class attribute of each matching element.

7. The public Elements removeclass(String className) removes the className from each matching element

8. The public Elements toggleclass(String className) reverses the class attribute of each matching element. (some are removed, none is added).

9. Public boolean hasclass(String className) detects if any of the matching elements have a given className value in the class attribute.

10, public String Val() Gets the value of the first matching element's form.

11. Public Elements Val(String value) sets the form value for each matching element.

12. Public String Text() gets a synthesis of all matching element texts. In some cases, this method will get duplicate data.

13, public boolean hasText() detect whether there is text content

14. Public String HTML() gets a synthesis of the internal HTML of all matching elements.

15. The public String outerhtml() gets a synthesis of the external HTML of all matching elements.

16, public String toString() Gets the combination of external HTML for all matching elements.

17. Public Elements tagName(String tagName) updates the tag name of each matching element. If you want to turn each <i> into a <em>, you can do this: Doc.select ("I"). TagName ("em");

18. Public Elements HTML(String HTML) sets the internal HTML for each matching element.

19. Public Elements prepend(String HTML) adds the specified HTML to the internal HTML opening of each matching element.

20. Public Elements Append(String html) adds the specified HTML to the end of the internal HTML for each matching element.

21. Public Elements before(String HTML) inserts the specified HTML before the external HTML of each matching element.

22. Elements after (String HTML) inserts the specified HTML after the external HTML of each matching element.

23. Public Elements Wrap(String HTML) wraps each matching element with the specified HTML.

For example, for this html:<p><b>this</b> is <b>jsoup</b></p>, execute this wrapper: Doc.select ("B"). Wrap (" <i></i> ") becomes:<p><i><b>this</b></i> is <i><b>jsoup</b ></i></p>

24. The public Elements Unwrap() removes the matching elements but retains their content.   Example:<div><font>one</font> <font><a href= "/" >Two</a></font></div> Executes Doc.select ("Font"). Unwrap () becomes: <div>one <a href= "/" >Two</a></div>
25. Public Elements Empty() clears the contents of each matching element. Example: <div><p>hello <b>there</b></p> <p>now</p></div> Executive Doc.select (" P "). Empty () into <div><p></p> <p></p></div>

26. The public Elements Remove () removes the matching element from the DOM tree. Example:<div><p>hello</p> <p>there</p> </div> execution Doc.select ("P"). Remove () later turned into <div> </div>

27. Public Elements Select(String query) queries a matching set of elements based on the query selector.

28. Public Elements not (String query) removes the set of filtered elements by removing the set of elements that match the selector.

29. The public Elements eq(int index) gets the matching element according to index

30. Public Boolean is (String query) detects if an element matches a given selector.

31. Public Elements Parents() gets all the parent-class elements and ancestor-element sets of the matching element set

32. The public element, first (), gets a matching element

33. The public element, last () gets the final matching element

34. Public Elements Traverse(Nodevisitor nodevisitor) performs a depth-first traversal of the element being queried.

35, the length of the public int size() element set.

36. Public Boolean IsEmpty() detection is null

37. Public Boolean contains(object o) detects whether a specified object is included

38. The public iterator<element> iterator() gets the iterator object

39, public object[] ToArray() converts an element set to an array

40, public <T> t[] toArray(t[] a)

41. New elements of public boolean add(element Element)

42. Public Boolean remove (Object o) removes the specified element

43. Public Boolean Containsall(collection<?> c) refers to the list or Collection usage in Java.

44. Public Boolean AddAll(collection< extends element> c) refers to the list or Collection usage in Java.

45, public boolean addall(int index, COLLECTION<? extends element> C) refer to the list or Collection usage in Java.

46. Public Boolean RemoveAll(collection<?> c) refers to the list or Collection usage in Java.

47. Public Boolean Retainall(collection<?> c) refers to the list or Collection usage in Java.

48. public void clear () empty element set

49. Public element get (int index) gets the specified element according to the index

50. Public element set(int index, element Element) specifies the element according to the index setting

51, public void add(int index, element Element) adds element at specified position

52, public element remove(int index) removes elements from the specified position

53. public int indexOf(Object o) Gets the index of the specified element (where it first appears)

54, public int lastindexof(Object o) Gets the position of the last occurrence of the specified element.

55, public listiterator<element> listiterator() specific reference list<element>

56, public listiterator<element> listiterator(int index) specific reference list<element>

57, public list<element> sublist(int fromindex, int toindex) gets a subset based on the starting point

Reprint please indicate the author and the source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.