Elements class of jsoup

Source: Internet
Author: User
Tags addall

I. Introduction

This class is located under the select package and directly inherited from the Object. All Implemented interfaces include Cloneable and Iterable. , Collection , List

Class Declaration: public classElementsExtends Object implements List , Cloneable

AvailableElement.select(String)Method To obtainElementsObject.

Ii. Constructor

1. publicElements() Default constructor
2. publicElements(Int initialCapacity) specifies an initial capacity to createElementsObject.

3. publicElements(Collection Elements) Use a known element set to create ElementsObject.

4. publicElements(List Elements) use the List set of known elements to create ElementsObject.

5. publicElements(Element... elements) createsElementsObject.

Iii. Detailed Method

1. public ElementsClone() Clone

2. public StringAttr(String attributeKey) obtain the First Matching Element Based on the key (matching means that this attribute is available ).

3. public booleanHasAttr(String attributeKey) if any element in the element set matches (with this attribute), true is returned.

4. public ElementsAttr(String attributeKey, String attributeValue) set the value of all elements matching the attributeKey to attributeValue.

5. public ElementsRemoveAttr(String attributeKey) removes any matching element from the element set.

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

7. public ElementsRemoveClass(String className) removes the className from each matching element.

8. public ElementsToggleClass(String className) reverses the class attribute of each matching element. (If yes, It is removed. If no, it is added ).

9. public booleanHasClass(String className) checks whether any matching element has a given className value in the class attribute.

10. public StringVal() Obtain the value of the first form matching element.

11. public ElementsVal(String value) set the form value for each matching element.

12. public StringText. This method may obtain duplicate data in some cases.

13. public booleanHasText() Check for text content

14. public StringHtml() Obtain the synthesis of the internal html of all matching elements.

15. public StringOuterHtml() Obtain the synthesis of external html of all matching elements.

16. public StringToString() Obtain the synthesis of external html of all matching elements.

17. public ElementsTagName(String tagName) Update the tag name of each matching element.ChangeYou can do this: doc. select ("I"). tagName ("em ");

18. public ElementsHtml(String html) set the internal html of each matching element.

19. public ElementsPrepend(String html) adds the specified html to the beginning of the internal html of each matching element.

20. public ElementsAppend(String html) adds the specified html to the end of the internal html of each matching element.

21. public ElementsBefore(String html) insert the specified html before the external html of each matching element.

22. public ElementsAfter(String html) insert the specified html after the external html of each matching element.

23. public ElementsWrap(String html) encapsulate each matching element with the specified html.

For example, for this html:

ThisIsJsoup

Run the following package: doc. select ("B"). wrap ("") Is changed:

ThisIsJsoup

24. public ElementsUnwrap() Remove matching elements but keep their content. Example: One Two executes doc. select ("font"). unwrap () to: One Two
25. public ElementsEmpty() Clears the content of each matching element. Example:

HelloThere

Now

Run doc. select ("p"). empty ()

26. public ElementsRemove() Remove matching elements from the DOM tree. Example:

Hello

There

Run doc. select ("p"). remove () and change

27. public ElementsSelect(String query) query the matched element set based on the query selector.

28. public ElementsNot(String query) removes the element set that matches the selector and returns the filtered element set.

29. public ElementsEq(Int index) according to the indexGet Matching Element

30. public booleanIs(String query) checks whether an element matches a given selector.

31. public ElementsParents() Obtain all the parent element and ancestor Element Set matching the element set.

32. public ElementFirst() Obtain the first matched element.

33. public ElementLast() Obtain the last matched element.

34. public ElementsTraverse(NodeVisitor nodeVisitor) executes a depth-first traversal of the queried elements.

35. public intSize() The length of the element set.

36. public booleanIsEmpty() Check whether it is empty

37. public booleanContains(Object o) checks whether the specified Object is included

38. public Iterator Iterator() Get the iterator object

39. public Object []ToArray() Convert the element set to an array

40. public T [] ToArray(T [])

41. public booleanAdd(Element element) New Element

42. public booleanRemove(Object o) Remove a specified Element

43. public booleanContainsAll(Collection C) refer to the List or Collection usage in java.

44. public booleanAddAll(Collection C) refer to the List or Collection usage in java.

45. public booleanAddAll(Int index, Collection C) refer to the List or Collection usage in java.

46. public booleanRemoveAll(Collection C) refer to the List or Collection usage in java.

47. public booleanRetainAll(Collection C) refer to the List or Collection usage in java.

48. public voidClear() Clear the Element Set

49. public ElementGet(Int index) Get the specified Element Based on the index

50. public ElementSet(Int index, Element element) specifies an Element based on index settings

51. public voidAdd(Int index, Element element) add an Element at the specified position

52. public ElementRemove(Int index) Removes elements at a specified position.

53. public intIndexOf(Object o) to obtain the index of the specified Element (the first location)

54. public intLastIndexOfObject o.

55. public ListIterator ListIterator() For details, refer to List

56. public ListIterator ListIterator(Int index) For details, refer to List

57. public List SubList(Int fromIndex, int toIndex) Obtain a subset based on the starting point.

Reprinted, please indicate the author and Source

Related Article

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.