KsoupElementAdapter

class KsoupElementAdapter(val backing: Element) : KpaStruct(source)

Adapter exposing a KSoup Element as a KpaStruct.

The struct's keys are the element's attribute names — KSoup's own iterator already excludes internal attributes (those whose key starts with /) — followed by the distinct tag names of its child elements. When an attribute and a child element share a name, the attribute wins and the like-named child elements are not reachable through that key. A child tag that occurs once resolves to a nested KsoupElementAdapter; a child tag that occurs two or more times resolves to a KsoupElementListAdapter over those elements in document order. Text and other non-element nodes are not represented.

In addition to those data keys, get and contains recognize a reserved set of synthetic =-prefixed accessors that are not listed in keys or toMap: =ownText, =text, =wholeText, =wholeOwnText, =html, and =outerHtml each resolve to a KsoupTextAdapter built from the like-named Element method (=outerHtml from outerHtml(), the element's serialized markup including its own tags). A key of the form =child:NAME resolves to the child element(s) named NAME, ignoring any attribute of the same name — the opposite of the default attribute-wins tiebreak — and follows the same single-vs-repeat rule (one match resolves to a nested KsoupElementAdapter; two or more resolve to a KsoupElementListAdapter). A key of the form =children:NAME also ignores a like-named attribute but is shape-stable: when it resolves it is always a KsoupElementListAdapter (never a collapsed single struct), and it resolves to null when no child is named NAME — so contains is true for a =children: key exactly when at least one such child exists.

Parameters

backing

The underlying KSoup Element (a KSoup Document is also an Element).

Constructors

Link copied to clipboard
constructor(backing: Element)

Properties

Link copied to clipboard
val backing: Element
Link copied to clipboard
open override val keys: Set<String>

The attribute names (excluding internal attributes) and distinct child tag names of backing.

Functions

Link copied to clipboard
open operator override fun contains(key: String): Boolean
Link copied to clipboard
open operator override fun get(key: String): KpaElement?

Resolves key to a KpaElement. A reserved text accessor (=ownText, =text, =wholeText, =wholeOwnText, =html, or =outerHtml) yields a KsoupTextAdapter built from the like-named Element method. Any other key resolves to the matching attribute or child tag.

Link copied to clipboard
open override fun toMap(): Map<String, KpaElement>