Nim icon indicating copy to clipboard operation
Nim copied to clipboard

add elemText proc to xmltree

Open LaughingBubba opened this issue 1 year ago • 2 comments

text* proc cannot be used with an xnElement type. elemText* is intended to fill that gap.

This proc gets the associated text for an element node n. Finds all the top level text nodes for an element and returns a concatenated string of their contents. An optional string can be passed to be used as a text node separator.

If there are no text nodes, an empty string is returned.

LaughingBubba avatar Aug 04 '22 12:08 LaughingBubba

I didn't check the PR in detail, but how is this different from xmltree.innerText - https://nim-lang.org/docs/xmltree.html#innerText%2CXmlNode?

Yardanico avatar Aug 05 '22 08:08 Yardanico

innerText does all nodes with an fText property and ripples through all the child nodes of a node.

elemText only does the top level xnText's nodes for only an xnElement. AFAIK there is no equivalent proc in the xmltree library.

Mr Rumpf didn't like my last effort but left instructions as to what would be acceptable. Check the closed PR here

LaughingBubba avatar Aug 05 '22 08:08 LaughingBubba

Just curious, do other language's XML libraries have an equivalent to this? If so, what is it called?

Varriount avatar Sep 21 '22 22:09 Varriount

plainText or stripTags would be better names.

Araq avatar Oct 03 '22 04:10 Araq

it's like innerText and textContent in html

bung87 avatar Aug 05 '23 21:08 bung87

If in doubt, leave it out. These things never exactly do what you need anyway and you're better off with custom logic instead.

Araq avatar Aug 10 '23 15:08 Araq