Overview Units Class Hierarchy Classes, Interfaces, Objects and Records Types Variables Constants Functions and Procedures Identifiers |
Class TTreeNode
Unit
simplehtmltreeparser
Declaration
type TTreeNode = class(TObject)
Description
This class representates an element of the html file
It is stored in an unusual tree representation: All elements form a linked list and the next element is the first children, or if there is none, the next node on the same level, or if there is none, the closing tag of the current parent. E.g. a xml file like <foo><bar>x</bar></foo> is stored as a quadro-linked list:
/---------------------------------\
| | ----------- | link to parent (for faster access, it would work without it)
\|/ | \|/ | |
' '
<foo> <---> <bar> <---> x <---> </bar> <---> </foo> double linked list of tags (previous link again for faster access, a single linked list would work as well)
. . . .
/|\ /|\ /|\ /|\
| ----------------------- | single linked of corresponding node
---------------------------------------------------
There are functions (getNextSibling, getFirstChild, findNext, ...) to access it like a regular tree, but it is easier and faster to work directly with the list. Some invariants: (SO: set of opening tags in sequence) ∀a \in SO: a < a.reverse ∀a,b \in SO: a < b < a.reverse => a < b.reverse < a.reverse Attributes should be accessed with the getAttribute or getAttributeTry method. Or you can enumerate them all for attrib in attributes , if attributes is not nil. #)
Hierarchy
Overview
Fields
Methods
Properties
Description
Fields
 |
value: string; |
tag name for open/close nodes, text for text/comment nodes
|
 |
next: TTreeNode; |
next element as in the file (first child if there are childs, else next on lowest level), so elements form a linked list
|
 |
previous: TTreeNode; |
previous element (self.next.previous = self)
|
 |
reverse: TTreeNode; |
element paired by open/closing, or corresponding attributes
|
 |
offset: longint; |
count of characters in the document before this element (so document_pchar + offset begins with value)
|
Methods
 |
procedure deleteAll(); |
deletes the tree
|
 |
procedure changeEncoding(from,toe: TSystemCodePage; substituteEntities: boolean; trimText: boolean); |
converts the tree encoding from encoding from to toe, and substitutes entities (e.g ä)
|
 |
function findNext(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]; sequenceEnd: TTreeNode = nil):TTreeNode; |
Returns the element with the given type and text which occurs before sequenceEnd. This function is nil-safe, so if you call TTreeNode(nil).findNext(...) it will return nil
|
 |
function findChild(withTyp: TTreeNodeType; const withText:string; findOptions: TTreeNodeFindOptions=[]): TTreeNode; |
Find a matching direct child (equivalent to findNext with certain parameters, but easier to use) A direct child of X is a node Y with Y.parent = X. The options tefoNoChildren, tefoNoGrandChildren have of course no effect. (former is set to false, latter to true)
|
 |
function deepNodeText(separator: string=''):string; |
concatenates the text of all (including indirect) text children
|
 |
function outerXML(insertLineBreaks: boolean = false):string; |
|
 |
function innerXML(insertLineBreaks: boolean = false):string; |
|
 |
function outerHTML(insertLineBreaks: boolean = false):string; |
|
 |
function innerHTML(insertLineBreaks: boolean = false):string; |
|
 |
function getValue(): string; |
get the value of this element
|
 |
function getValueTry(out valueout:string): boolean; |
get the value of this element if the element exists
|
 |
function hasAttribute(const a: string; const cmpFunction: TStringComparisonFunc = nil): boolean; |
returns if an attribute with that name exists. cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttribute(const a: string):string; overload; |
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttribute(const a: string; const cmpFunction: TStringComparisonFunc):string; overload; |
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttribute(const a: string; const def: string; const cmpFunction: TStringComparisonFunc = nil):string; overload; |
get the value of an attribute of this element or '' if this attribute doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttributeTry(const a: string; out valueout: string; const cmpFunction: TStringComparisonFunc = nil):boolean; |
get the value of an attribute of this element and returns false if it doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttributeTry(a: string; out valueout: TTreeAttribute; cmpFunction: TStringComparisonFunc = nil):boolean; |
get the value of an attribute of this element and returns false if it doesn't exist cmpFunction controls is used to compare the attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getAttributeCount(): integer; |
|
 |
function getPreviousSibling(): TTreeNode; |
Get the previous element on the same level or nil if there is none
|
 |
function getNextSibling(): TTreeNode; |
Get the next element on the same level or nil if there is none
|
 |
function getFirstChild(): TTreeNode; |
Get the first child, or nil if there is none
|
 |
function getParent(): TTreeNode; |
Searchs the parent, notice that this is a slow function (neither the parent nor previous elements are stored in the tree, so it has to search the last sibling)
|
 |
function getPrevious(): TTreeNode; |
Searchs the previous, notice that this is a slow function (neither the parent nor previous elements are stored in the tree, so it has to search the last sibling)
|
 |
function getRootHighest(): TTreeNode; |
Returns the highest node ancestor
|
 |
function getRootElement(): TTreeNode; |
Returns the highest element node ancestor
|
 |
function hasDocument(): boolean; |
Returns if this node is contained in a document
|
 |
function getNodeName(): string; |
Returns the name as namespaceprefix:name if a namespace exists, or name otherwise. Only attributes, elements and PIs have names.
|
 |
function getNamespacePrefix(): string; |
Returns the namespace prefix. (i.e. 'a' for 'a:b', '' for 'b')
|
 |
function getNamespaceURL(): string; |
Returns the namespace url. (very slow, it searches the parents for a matching xmlns attribute) cmpFunction controls is used to compare the xmlns: attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
function getNamespaceURL(prefixOverride: string; cmpFunction: TStringComparisonFunc = nil): string; |
Returns the url of a namespace prefix, defined in this element or one of his parents cmpFunction controls is used to compare the xmlns: attribute name the searched string. (can be used to switch between case/in/sensitive)
|
 |
procedure getOwnNamespaces(var list: TNamespaceList); |
Returns all namespaces declared or used in this element and its attributes
|
 |
procedure getAllNamespaces(var list: TNamespaceList; first: boolean = true); |
Returns all namespaces declared/used by this element and all ancestors
|
 |
function isNamespaceUsed(const n: INamespace): boolean; |
Tests if a namespace is used by this element or any child (same prefix + url)
|
 |
procedure insertSurrounding(before, after: TTreeNode); |
Surrounds self by before and after, i.e. inserts "before" directly before the element and "after" directly after its closing tag (slow)
|
 |
procedure insertSurrounding(basetag: TTreeNode); |
inserts basetag before the current tag, and creates a matching closing tag after the closing tag of self (slow)
|
 |
procedure addAttribute(const aname, avalue: string; const anamespace: TNamespace = nil); inline; |
|
 |
procedure addNamespaceDeclaration(n: INamespace; overridens: boolean ); |
|
 |
procedure removeElementFromDoubleLinkedList; |
|
 |
function deleteElementFromDoubleLinkedList: TTreeNode; |
|
 |
function toString(): string; reintroduce; |
converts the element to a string (not recursive)
|
 |
function toString(includeText: boolean; includeAttributes: array of string): string; reintroduce; |
converts the element to a string (not recursive)
|
 |
constructor create(); virtual; |
|
 |
constructor create(atyp: TTreeNodeType; avalue: string = ''); virtual; |
|
 |
class function createElementPair(const anodename: string): TTreeNode; |
|
 |
destructor destroy(); override; |
|
 |
procedure initialized; virtual; |
is called after an element is read, before the next one is read (therefore all fields are valid except next (and reverse for opening tags))
|
 |
function caseInsensitiveCompare(const a,b: string): boolean; |
returns true if a=b case insensitive. Can be passed to getAttribute
|
 |
function caseSensitiveCompare(const a,b: string): boolean; |
returns true if a=b case sensitive. Can be passed to getAttribute
|
 |
class function compareInDocumentOrder(const a,b: TTreeNode): integer; static; |
|
Properties
 |
property defaultProperty[name:string]: string read getAttribute; |
|
Generated by PasDoc 0.14.0.
|